填空题若有如下程序: sub(int*y) while(--(*y)); printf("%d",(*y)--); main() int x=10; sub(&x); 则程序运行后的输出结果是 【13】 。
填空题下列给定程序中,函数proc()的功能是:用下面的公式求π的近似值,直到最后一项的绝对值小于指定的数(参数num)为止。
π/4≈1-1/3+1/5-1/7+…
例如,程序运行后,输入0.0001,则程序输出3.1414。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
float proc(float num)
{
int s;
float n,t,pi;
t=1;pi=0;n=1;s=1;
//****found****
while(t>=num)
{
pi=pi+t;
n=n+2;
s=-s;
//****found****
t=s%n;
}
pi=pi*4;
return pi;
}
void main()
{
float n1,n2;
system("CLS");
printf("Enter a float number:");
scanf("%f",
n2=proc(n1);
printf("%6.4f/n",n2);
}
填空题以下程序运行后的输出结果是______。
main()
{
int a,b,c;
a = 25;
b = 025;
c = 0x25;
printf("%d %d %d/n",a,b,C) ;
}
填空题下面程序用来输出结构体变量a所占存储单元的字节数,请填空。 main() struct stu char x[20];float y; a; printf("a size:%d/n",sizeof( 【14】 ));
填空题有以下程序:
#include <stdio.h>
main()
{ char ch1,ch2;int n1,n2;
ch1=getchar();ch2=getehar();
n1=ch1-'0'; n2=n1*10+(ch2-'0');
printf("%d/n",n2);
}
程序运行时输入:12<回车>,执行后的输出结果是{{U}} 【9】 {{/U}}。
填空题函数main()的功能是在带头结点的单链表中查找数据域中值最小的结点。请填空。 #include<stdio.h> struct node int data; struct node*next: ; int min(struct node*first)/*指针first为链表头指针*/ strct node *p;int m; p=first->next;m=p->data;p=p->next; for(; p!=NULL;p=) if(p->datadata<m)m=p->data; return m;
填空题下列给定程序中函数fun的功能是:求三个数的最小公倍数。
例如,若给主函数中的变量x1、x2、x3分别输入15112,则输出结果应当是330。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
/**********found**********/
fun(int x, y, z)
{
int j, t, n, m;
j=1;
t=j%x; m=j%y;
n=j%z;
while(t!=0||m!=0||n!=0)
{
j=j+1;
t=j%x;
m=j%y;
n=j%z;
}
/**********found**********/
return i;
}
main()
{
int x1, x2, x3, j;
printf("Input x1 x2 x3:");
scanf("%d%d%d",
printf("x1=%d, x2=%d, x3=%d/n", x1, x2, x3);
j=fun(x1, x2, x3);
printf("The minimal common multiple is: %d/n", j);
}
填空题给定程序中,函数fun的功能是:将形参s所指字符串中的数字字符转换成对应的数值,计算出这些数值的累加和作为函数值返回。
例如,形参s所指的字符串为abs5def126jkm8,程序执行后的输出结果为22。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int fun(char*s)
{int sum=0;
while(*s){
/*********found*********/
if(isdigit(*s))
sum+=*s-______;
/*********found*********/
______;
}
/*********found*********/
return ______;
}
main()
{char s[81]; int n;
printf("/nEnter a string:/n/n");
gets(s);
n=fun(s);
printf("/nThe result is:%d/n/n",n);
}
填空题以下程序运行后的输出结果是{{U}} 【9】 {{/U}}。
main()
{int X==1,y=0,a=0,b=0;
switch (x)
{case 1:switch (y)
{ case 0:a++;break;
case 1:b++;break;
}
case 2: a++;b++;break;
}
printf("%d%d/n",a,b);
}
填空题请补充函数fun(),该函数的功能是:只保留字符串中的大写字母,删除其他字符,结果仍保存在原来的字符串中,由全局变量m对删除后字符串的长度进行保存。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。 试题程序: #include<stdio.h> #include<conio.h> int m; void fun(char *s) int i=0,j=0; char *p=s; while (*(p+i)) if(*(p+i)>='A' 【3】 ; main() char str[80]; clrscr(); printf("/nEnter a string:"); gets(str); printf("/n/nThe string is:/%s/n",str); fun(str); printf("/n/nThe string of changing is:/%s/n",str); printf("/n/nThe length of changed string is:/%d/n",m);
填空题已有定义如下:
struct node
{ int data;
struct node *next;
} *p;
以下语句调用malloc函数,使指针p指向一个具有struct node类型的动态存储空间。请填空。 p = (struct node *)malloc(【 】);
填空题设a,b,c为整型数,且a=2,b=3,c=4,则执行完以下语句后,a的值是 【8】 。 a*=16+(b++)-(++c);
填空题若输入5、9,以下程序的运行结果为 【10】 。main() int a,b,*pt1,*pt2; printf("input a,b:"); scanf("%d%d",&a,&b); pt1=&a; pt2=&b; if(a<b) swap(pt1,pt2); printf("/n%d,%d/n",*pt1,*pt2);swap(p1,p2)int *p1,*p2; int *p; p=p1; p1=p2; p2=p;
填空题以下程序运行后的输出结果是______。
main()
{ int a[4][4]={{1,2,3,4},{5,6,7,8},{11,12,13,14},{15,16,17,18}};
int i=0,j=0,s=0;
while (i++<4)
{ if(i==2||i==4) continue;
j=0;
do { s+=a[i][j]; j++;}while(j<4);
}
printf("%d/n",s);
}
填空题下列程序的输出结果是______。
#include<stdio.h>
main()
{int x=10,y=10,i;
for(i=0;x>8;y=++i)
printf("%d%d",x--,y);
}
填空题数据结构分为逻辑结构和存储结构,循环队列属于 【2】 结构。
填空题若x为int类型,请写出与!x等价的C语言表达式______。
填空题请补充main()函数,该函数的功能是:先以只写方式打开文件file.dat,再把字符串s中的字符保存到这个磁盘文件中。请勿改动main()函数与其他函数中的任何内容,仅在的横线上填写所需的若干表达式或语句。
注意:部分源程序给出如下。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#define N 100
void main()
{
FILE*f;
int i=0;
char ch;
chair s[N]="Welcome!";
if((f=fopen|("______", "w"))==NULL)
{
printf("cartnot open file.dat/n");
exit(0);
}
while(s[i])
{
ch=s[i];
______;
putchar(ch);
i++;
}
______;
}
填空题有以下程序段,且变量已正确定义和赋值。
for(s=1.0, k=1; k<=n;k++) s=s+1.0/(k*(k/1));
printf("s=%f/n/",s);
请填空,使下面程序段的功能与之完全相同。
s=1.0; k=1;
while({{U}} 【10】 {{/U}}) { s=s+1.0/(k*(k+1)); {{U}}【11】 {{/U}}; }
printf("s-=%f/n/n",s);
填空题给定程序MODI1.C中函数fun的功能是计算n!。
例如,给n输入5,则输出120.000000。
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
给定源程序如下。
#include<stdio.h>
double fun(int n)
{ double result=1.0;
/************found***************/,
if n==0
return 1.0;
while(n>1
}
main()
{ int n;
printf("Input N:");
scanf("%d",
printf("/n/n%d!=%lf/n/n",n,fun(n));
}
