填空题给定程序中,函数fun()的功能是找出100~999之间(含100和999)所有整数中各位上数字之和为x(x为一正整数)的整数,然后输出;符合条件的整数个数作为函数值返回。 例如,当x值为5时,100~999之间各位上数字之和为5的整数有104、113、122、131、140、203、212、221、230、302、311、320、401、410、500,共15个。当x值为27时,各位数字之和为27的整数是999,只有1个。 #include<stdio.h> int fun(int x) int n,s1,s2,s3,t; n=0; t=100; /**********found**********/ While(t<= (1) ) /**********found**********/ s1=t%10;s2= (2) %10;s3=t/100; /**********found**********/ If(s1+s2+s3= (3) ) printf("%d",t); n++; t++; return n; main() int x=-1; While(x<0) printf("Please input(x>0):"); Scanf("%d", Printf("/nThe result is:%d/n",fun(x));
填空题以下程序运行时若从键盘输入:10 20 30<回车>,输出结果是{{U}} 【10】 {{/U}}。
# include<stdio.h>
main()
{ int i=0,j=0,k=0;
scanf("%d% *d%d",printf("%d %d %d/n",i,j,k);
}
填空题请补充main()函数,该函数的功能是:从字符串str中取出所有数字字符,并分别计数,然后把结果保存在数组tt中并输出,把其他字符保存在tt[10]中。
例如,当str1=“00237481367539dfji”时,结果为
0:21:12:13:34:15:16:17:28:19:1
other charactor:4
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main()
int i,tt[11];
char*str="00237481367539dfji";
char*p=str;
syslem("CLS");
printf("***the origial data***/n");
puts(str);
for(i=0;i<11;i++)
tt[i]=0;
while(*p)
{
switch(______)
{
case"0":tt[0]++;break;
case"1";tt[1]++;break;
case"2":tt[2]++;break;
case"3":tt[3]++;break;
case"4":tt[4]++;break;
case"5":tt[5]++;break;
case"6":tt[6]++;break;
case"7":tt[7]++;break;
case"8":tt[8]++;break;
case"9":tt[9]++;break;
______
}
______
}
printf("****the result****/n");
for(i=0;i<10;i++)
printf("/n%d:%d",i,tt[i]);
printf("/nother charactor:%d",tt[i]);
}
填空题若有定义:int a=5, b=2, c=1; ,则表达式a-b<c||b==c的值是______。
填空题以下程序打开新文件f.txt,并调用字符输出函数将a数组中的字符写入其中,请填空。 #include <stdio.h> main() ______*fp; char a[5]='1','2','3','4','f5',i; f=fopen("______","w"); for(i=0;1<5;i++)fputc(a[i],fp); fclose(fp);
填空题以下程序的功能是输出如下形式的方阵:
13 14 15 16
9 10 11 12
5 6 7 8
1 2 3 4
请填空。
main()
{int i,j,x;
for(j=4;j{{U}} 【17】{{/U}};j--)
{for(i=1;i<=4;i++)
{x=(j-1)*4 +{{U}} 【18】 {{/U}};
printf("%4d",x);
}
printf("/n");
}
}
填空题下列程序的运行结果为{{U}} 【8】 {{/U}}。
main()
{ int a[3]C4}={{1,3,5,7},{2,4,6,8},{15,17,34,12}};
printf("max value is %d/n",max value(3,4,a));
}
max value(m,n,array)
int m,n,array[][4];
{ int i,j,max;
max=array[0][0];
for(i=0;i<m;i++)
for(i=0;i<n;j++)
if(max<array[i][j])max=array[i][j];
return(max);
}
填空题以下程序的运行结果是: 【14】 。 #include <stdio.h> #include <string.h> char *ss(char *s) return s+strlen(s)/2; main() char *p,*str="abcdefgh"; p=ss(str);printf("%s/n",p);
填空题以下函数用来求出2个整数之和,并通过形参将结果传回。 void func(int x, int y, 【6】 z) *z=x+y;
填空题阅读下面程序,则程序的执行结果为______。
#include"stdio.h"
main()
{int a=10;
fun(a);
printf("%d/n",a);}
fun(int x)
{x=50;}
填空题以下程序运行时,若从键盘输入:10 20 30<回车>。输出结果是______。
#include <stdio.h>
main()
{ int i=0,j=0,k=0;
acanf("%d%*d%d",printf("%d%d%d/n",I,j,k);
填空题下列给定程序中,函数fun和funx的功能是:用二分法求方程2x3-4x2+3x-6=0的一个根,并要求绝对误差不超过0.001。 例如,若给m输入-100,n输入90,则函数求得的一个根为2.000。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdio.h> #include<math.h> double funx(double x) return(2*x*x*x-4*x*x+3*x-6); double fun(double m,double n) /***********found**********/ int r; r=-(m+n)/2; /************found***********/ while(fabs(n-m)<0.001) if(funx(r)*funx(n)<0)m=r; else n=r; r=(m+n)/2; return r; main() double m,n,root; printf("Enter m n:/n"); scanf("%lf%lf",&m,&n); root=fun(m,n); printf("root=%6.3f/n",root);
填空题函数main()的功能是:在带头节点的单链表中查找数据域中值最小的节点。请填空。
#include<stdio.h>
struct node
{ int data;
struct node*next;
}
int main<struct node*first)/*指针first为链表头指针*/
{ struct node*p;int m;
P=first->next;m=P->data;p=p->next;
for(;P!=NULL;p=______)
if(p->data<m)m=p->data;
return m;
}
填空题下面程序把从终端读入的10个整数以二进制的方式写到一个名为bi.dat的新文件中。请填空。 #include<stdio.h> FILE * fp; main() int i,j; if((fp=fopen( 【19】 ,"wb"));=NULL)exit(0); for(i=0;i<10;i++) scanf("%d",&j); fwrite(&j,sizeof(int),1, 【20】 ); fclose(fp);
填空题若有以下程序
main()
{ int a[4][4]={{1,2,-3,-4},{0,-12,-13,14} ,{-21,23,0,-24},{-31,32,-33,0}};
int i,j,s=0;
for(i=0;i<4;i++)
{ for(j=0;j<4;j++)
{ if(a[i][j]<0) continue;
if(a[i][j]==0) break;
s+=a[i][j];
}
}
printf("%d/n",s);
}
执行后输出结果是{{U}}【10】{{/U}}。
填空题已知字母A的ASCII码为65。以下程序运行后的输出结果是 【11】 。 main() char a,b; a='A'+'5'-'3';b=a+'6'-'2'; printf("%d %c/n",a,B) ;
填空题以下程序运行后,当输入“14 63”时,输出结果是______。 #include<stdio.h> main() int m, n; scanf("%d %d", while(m!=n) while(m>n) m=m-n; while(m<n) n=n-m; printf("%d/n", m);
填空题fseek函数的正确调用形式是 【14】 。
填空题在长度为n的线性表中,寻找最大项至少需要比较______次。
填空题下列给定程序中,函数fun()的功能是:从n个学生的成绩中统计出高于平均分的学生人数,人数由函数值返回,平均分存放在形参aver所指的存储单元中。例如输入8名学生的成绩:
85 65.5 69 95.5 87 55 62.5 75
则高于平均分的学生人数为4(平均分为74.312500)。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <conio.h>
#define N 20
int fun(float *s,int n,float *aver)
{
/*************found*************/
int ave,t=0;
int count=0,k,i;
for(k=0;k<n;k++)
t+=s[k];
ave=t/n;
for(i=0;i<n;i++)
/*************found***************/
if(s[i]<ave)
count++;
/*************found*************/
aver=ave;
return count;
}
main()
{
float s[30],aver;
int m,i;
clrscr();
printf("/nPlease enter m:");
scanf("%d",&m);
printf("/nPlease enter%d mark:/n",m);
for(i=0;i<m;i++)
scanf("%f",s+i);
printf("/nThe number of students:%d/n",
fun(s,m,&aver));
printf("Ave=%f/n",aver);
}
