C语言程序填空题及答案(共8页).doc
精选优质文档-倾情为你奉上 程序填空题1、#include <stdio.h>void main() int n,k=0; scanf("%d",&n);while( _1_ ) / 1)n 2) n!=0; k+; _2_; n=n/10 printf("%dn",k);2、#include <stdio.h>#include <math.h>#define f(x) x*x-5*x+sin(x)void main() int x; float max; _1_ / max=f(1); for(x=2;x<=10;x+) _2_ / if(f(i)>max) max=f(i); printf("%fn",max);3、#include <stdio.h>void main() char c; c=getchar(); if(_1_) / c>='a' && c<'v' c=c+5; else if (c>='v' && c<='z') _2_ /c=c-21; putchar(c);4、#include <stdio.h>void Dec2Bin(int m) int bin32,j; for(j=0;m!=0;j+) binj= _1_; / m%2 m=m/2; for(;j!=0;j-) printf("%d", _2_ ); / binj-1void main() int n; scanf("%d",&n); Dec2Bin(n);5、#include <stdio.h> #include <math.h> void main() int n,s=0; scanf("%d",&n); _ 1 _ /n=(n>0?n:-n) ; 2)n=fabs(n); while(n!=0) _ 2 _ / s=s+n%10; n=n/10; printf("%dn",s); 6、/#include <stdio.h>void swap(_1_) /int *pa , int *pb /*交换两个数的位置*/ int temp; temp = *pa; *pa = *pb; *pb = temp;void main() int a,b,c,temp; scanf("%d%d%d",&a,&b,&c); if(a>b) swap(&a,&b); if(b>c) swap(&b,&c); if(_2_) / a>b swap(&a,&b); printf("%d,%d,%d",a,b,c);7、#include <stdio.h>_1_ /long f(int n);void main() printf("%ldn",f(30);long f(int n) if( _2_ ) / n=1|n=2 return 1; else return f(n-1)+f(n-2);8、#include <stdio.h>void main() char s80; int i,j; gets(s); for(i=j=0;_1_;i+) / si!=0 if(si != 'c') sj=si; _2_ /j+; sj='0' puts(s);9、#include <stdio.h>struct STUDENT char name16; int math; int english; int computer; int average;void GetAverage(struct STUDENT *pst) /* 计算平均成绩 */ int sum=0; sum = _1_; /sum+ pst->math+ pst->English+ pst->computer pst->average = sum/3;void main() int i; struct STUDENT st4="Jessica",98,95,90,"Mike",80,80,90, "Linda",87,76,70,"Peter",90,100,99; for(i=0;i<4;i+) GetAverage(_2_); / &sti printf("NametMathtEnglishtComputAveragen"); for(i=0;i<4;i+) printf("%st%dt%dt%dt%dn",sti.name,sti.math,sti.english, sti.computer,sti.average); 10、#include <stdio.h>#include <math.h>long f(long n) long m,y=0; m=fabs(n); while(m!=0) y=y*10+m%10; _1_ / m=m/10; if(n>=0) return y; else _2_ / return ( -y);void main() printf("%ldt",f(12345); printf("%ldn",f(-34567);11、#include <stdio.h>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 float y=a0,t=1; int i; for(i=1;i<n;i+) t=t*x; y=y+ai*t; _2_ / return y 12、#include <stdio.h>#include <string.h>#include <ctype.h>void f(char *s) int i=0; while(si!='0') if(isdigit(si) _1_(s+i,s+i+1); / strcpy _2_ i+; / elsevoid main() char str80; gets(str); f(str); puts(str);13、#include <stdio.h>#include <ctype.h>void main() char a80; int n3=0,i; gets(a); _1_ /for(i=0;ai!=0;i+) if (tolower(ai)>='a' && tolower(ai)<='z') /*统计字母个数*/ n0+; else if (_2_) /*统计数字个数*/ ai>='0' && ai<='9'n1+; else n2+; for(i=0;i<3;i+) printf("%dn",ni); 14、#include <stdio.h>#include<math.h>void main()int i,a,b,c;for(i=100;i<=999;i+)a=i/100;_1_ / b=i%100/10;c=i%10;if (_2_) /i=a*a*a+b*b*b+c*c*cprintf("%d is a Armstrong number!n",i);15、#include <stdio.h>void main() int a10,b10,i; printf("nInput 10 numbers: "); for (i=0; i<10;i+) /* 数组输入 */ scanf("%d", &ai); for (i=1; i<10; i+) bi=_1_; /* 计算b数组中的元素 */ /ai+ai-1 for (i=1; i<10; i+) printf("%3d",bi); if (_2_) printf("n"); /* 每行打印3个数据 */ /i%3=0 专心-专注-专业