《C语言程序填空题及答案》由会员分享,可在线阅读,更多相关《C语言程序填空题及答案(8页珍藏版)》请在金锄头文库上搜索。
1、-程序填空题程序填空题1、#include void main()int n,k=0;scanf(%d,&n);while( _1_ )/ 1)n/ 1)n2) n!=0;2) n!=0;k+;_2_;n=n/10n=n/10printf(%dn,k);2、#include #include #define f(x) x*x-5*x+sin(x)void main()int x; float max;_1_/max=f(1);max=f(1);for(x=2;xmax)if(f(i)max)max=f(i);max=f(i);printf(%fn,max);3、-. word.zl-#incl
2、ude void main()char c;c=getchar();if(_1_)/ c=a & c=a & c=v & c=z)_2_/c=c-21;/c=c-21;putchar(c);4、#include void Dec2Bin(int m)int bin32,j;for(j=0;m!=0;j+)binj= _1_;/ m%2/ m%2m=m/2;for(;j!=0;j-)printf(%d, _2_ );/binj-1binj-1void main()int n;scanf(%d,&n);Dec2Bin(n);5、-. word.zl-#include #include void m
3、ain()int n,s=0;scanf(%d,&n);_ 1 _/n=(n0?n:-n)/n=(n0?n:-n) ; ; 2) 2)n=fabs(n);n=fabs(n);while(n!=0) _ 2 _/ s=s+n%10;/ s=s+n%10;n=n/10;printf(%dn,s);6、/#include void swap(_1_)/int *pa , int *pb/int *pa , int *pb /*交换两个数的位置*/int temp;temp = *pa;*pa = *pb;*pb = temp;void main()int a,b,c,temp;scanf(%d%d%
4、d,&a,&b,&c);if(ab)swap(&a,&b);if(bc)swap(&b,&c);if(_2_)/ ab/ ab-. word.zl-swap(&a,&b);printf(%d,%d,%d,a,b,c);7、#include _1_/long f(int n)long f(int n);void main()printf(%ldn,f(30);long f(int n)if( _2_ )/ n=1|n=2/ n=1|n=2return 1;elsereturn f(n-1)+f(n-2);8、#include void main()char s80;int i,j;gets(s)
5、;for(i=j=0;_1_;i+)/ si!=0if(si != c)sj=si;_2_/j+;/j+;-. word.zl-sj=0;puts(s);9、#include struct STUDENTchar name16;int math;int english;int puter;int average;void GetAverage(struct STUDENT *pst)/* 计算平均成绩 */int sum=0;sum = _1_;/sum+ pst-math+ pst-English+pst-puterpst-average = sum/3;void main()int i;s
6、truct STUDENT st4=Jessica,98,95,90,Mike,80,80,90,Linda,87,76,70,Peter,90,100,99;for(i=0;i4;i+)GetAverage(_2_);/ &stiprintf(NametMathtEnglishtputAveragen);for(i=0;i4;i+)printf(%st%dt%dt%dt%dn,sti.name,sti.math,sti.english,sti.puter,sti.average);10、-. word.zl-#include #include long f(long n)long m,y=0
7、;m=fabs(n);while(m!=0) y=y*10+m%10;_1_/ m=m/10;/ m=m/10;if(n=0) return y;else _2_/return ( -y);return ( -y);void main()printf(%ldt,f(12345);printf(%ldn,f(-34567);11、#include float f(float,float*,int);void main()float b5=1.1,2.2,3.3,4.4,5.5;printf(%fn,f(1.7,b,5);float f( _1_ )/ float x,float a, int n
8、float x,float a, int nfloat y=a0,t=1; int i;for(i=1;in;i+) t=t*x; y=y+ai*t; _2_/return yreturn y12、-. word.zl-#include #include #include void f(char *s) int i=0;while(si!=0)if(isdigit(si) _1_(s+i,s+i+1);/ strcpy_2_i+;/void main() char str80;gets(str); f(str); puts(str);13、else#include #include void
9、main()char a80; int n3=0,i; gets(a);_1_/for(i=0;ai!=0;i+)if (tolower(ai)=a & tolower(ai)=0 & ai=9n1+;elsen2+;for(i=0;i3;i+) printf(%dn,ni);14、#include #includevoid main()-. word.zl-int i,a,b,c;for(i=100;i=999;i+)a=i/100;_1_/ b=i%100/10;/ b=i%100/10;c=i%10;if (_2_)/i=a*a*a+b*b*b+c*c*c/i=a*a*a+b*b*b+c*c*cprintf(%d is a Armstrong number!n,i);15、#include void main()int a10,b10,i;printf(nInput 10 numbers:);for (i=0; i10;i+)/* 数组输入 */scanf(%d, &ai);for (i=1; i10; i+)bi=_1_;/* 计算 b 数组中的元素 */ai+ai-1/ai+ai-1for (i=1; i10; i+)printf(%3d,bi);if (_2_)printf(n);/* 每行打印 3 个数据 */i%3=0/i%3=0-. word.zl-