首页 计算机二级C语言题库之程序填空

计算机二级C语言题库之程序填空

举报
开通vip

计算机二级C语言题库之程序填空计算机二级C语言题库之程序填空                                                 找Armstrong(水仙花)数:371=3*3*3+7*7*7+1*1*1 #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; ...

计算机二级C语言题库之程序填空
计算机二级C语言题库之程序填空                                                 找Armstrong(水仙花)数:371=3*3*3+7*7*7+1*1*1 #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________)    //  a*a*a+b*b*b+c*c*c = = i printf("%d is a Armstrong number!\n",i); } } 输入1个整数后,输出该数的位数。(例:输入3214则输出4,输入-23156则输出5)。 #include <stdio.h> void main() {  int n,k=0; scanf("%d",&n); while( _____1_____ ){        // n!=0 k++; _____2_____;          // n=n/10 } printf("%d\n",k); } 求输入的整数各位数字之和,如输入234则输出9,输入-312则输出6。 #include <stdio.h> #include <math.h> void main() { int n,s=0; scanf("%d",&n); ______ 1 ______        //  if (n<0) n=-n; while(n!=0) { ______ 2 ______      //  s+=n%10; n=n/10; } printf("%d\n",s); } 调用函数f,将一个整数首尾倒置。例如:若程序输入12345,则输出54321;若程序输入-34567,则输出-76543。 #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("%ld\t",f(12345));  printf("%ld\n",f(-34567)); } 调用函数f,从字符串中删除所有的数字字符。 #include <stdio.h> #include <string.h> #include <ctype.h> void f(char *s) { int i=0; while(s[i]!='\0'){ if(isdigit(s[i])) ____1____(s+i,s+i+1);  //  strcpy ___2___  i++;}                  //  else } void main() { char str[80]; gets(str); f(str); puts(str); } 调用find函数在输入的字符串中查找是否出现"the"这个单词。如果查到返回出现的次数,如果未找到返回0。 #include <stdio.h> int find(char *str) { char *fstr="the"; int i=0,j,n=0;      while (str[i]!='\0') { for(______1______)                //  j=0; j<3; j++ if (str[j+i]!=fstr[j]) break; if (______2______) n++;            //  j>=3 i++; } return n; } void main() {  char a[80]; gets(a); printf("%d",find(a)); } 输入的一个小写字母,将字母循环后移5个位置后输出。例如:"a"变成"f","w"变成"b"。 #include <stdio.h> void main() {  char c; c=getchar(); if(______1______)                //  c>='a'&&c<='u' c=c+5; else if (c>='v' && c<='z') ______2______        //  c=(c-'a'+5)%26+'a'; putchar(c); } 将字符串s中所有的字符'c'删除。 #include <stdio.h> void main() {  char s[80]; int i,j; gets(s); for(i=j=0; ______1______; i++)      //  s[i] != '\0' if(s[i] != 'c') {  s[j]=s[i]; ______2______          //  j++;                                                 } s[j]='\0'; puts(s); } 对x=1,2,……,10,求f(x)=x*x-5*x+sin(x)的最大值。 #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(x)>max)  max=f(x); printf("%f\n",max); } 输入三个整数,按由小到大的顺序输出这三个数。 #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______)            // if ( a>b ) swap(&a,&b); printf("%d,%d,%d",a,b,c); } 调用函数f,去除数组中的负数,输入数组x[7],输出结果为:1  3  4  6 #include <stdio.h>          // 数组元素的删除 void f(int *a,int *m) {  int i, j ; for(i=0;i<*m;i++) if(a[i]<0) { for(j=i--;j<*m-1;j++) a[j]=a[j+1]; _____1_____;                //  *m = *m-1; } } void main() {  int i,n=7,x[7]={1,-2,3,4,-5,6,-7}; _______2_______;            //  f (x, &n) ; for(i=0;i<n;i++) printf("%5d",x[i]); printf("\n"); } 调用函数f计算代数多项式1.1+2.2*x+3.3*x*x+4.4*x*x*x+5.5*x*x*x*x当x=1.7时的值。 #include <stdio.h> float f(float, float*, int); void main() {  float b[5]={1.1, 2.2, 3.3, 4.4, 5.5 }; printf("%f\n", f(1.7,b,5) ); } float f( _______1________ )                //  float x, float *a, int n {  float y=a[0], t=1;  int i; for(i=1; i<n; i++)  {  t=t*x;  y=y+a[i]*t; } _____2_____                        //  return y; } 分别统计字符串中英文字母、数字、和其他字符出现的次数。 #include <stdio.h> #include <ctype.h> void main() {  char a[80];  int n[3]={0}, i;  gets(a) ; ________1________                  //  for ( i=0; a[i]!='\0'; i++) {if (tolower(a[i])>='a' && tolower(a[i])<='z') /*统计字母个数*/ n[0]++; else if (________2________)  /*统计数字个数*/    //  a[i]>='0' && a[i]<='9' n[1]++; else n[2]++; } for(i=0;i<3;i++) printf("%d\n",n[i]); } 将输入的十进制整数n通过函数DtoH函数转换为十六进制数,并将转换结果以字符串形式输出。(例如:输入十进制数79,将输出十六进制4f。) # include <stdio.h> # include <string.h> char trans(int x) { if(x<10) return '0'+x; else _______1________    // return  'a'+x-10; } int DtoH(int n,char *str) { int i=0; while(n!=0) { ________2________      // str[i]=trans(n%16); n/=16;i++;          }  return i-1; } void main() { int i,k,n; char *str;        scanf("%d",&n); k=DtoH(n,str); for (i=0;i<=k;i++) printf("%c",str[k-i]); } 将输入的十                                                 进制正整数n通过函数Dec2Bin转换为二进制数,并将转换结果输出。 #include <stdio.h> void Dec2Bin(int m) { int bin[32],j; for(j=0;m!=0;j++) { bin[j]= ______1______;              // m%2 m=m/2; } for( ; j!=0; j-- ) printf("%d", ______2______ );          // bin[j-1] } void main() { int n; scanf("%d",&n); Dec2Bin(n); } 数列的第1、2项均为1,此后各项值均为该项前二项之和。计算数列第30项的值。 #include <stdio.h> _______1______              //  long  f(int n);  或者  long  f(int); void main() {  printf("%ld\n",f(30)) ; } long f(int n) {  if( ______2______ )      //  n==1 || n==2 return 1; else return f(n-1)+f(n-2); } 该程序计算四位学生的平均成绩,保存在结构中,然后列表输出这些学生的信息。 #include <stdio.h> struct STUDENT {  char name[16]; int math; int english; int computer; int average; }; void GetAverage(struct STUDENT *pst)    /* 计算平均成绩 */ {  int sum=0; sum = ______1______;          // pst->math+pst->english+pst->computer pst->average = sum/3; } void main() {  int  i; struct STUDENT st[4]={{"Jessica",98,95,90},{"Mike",80,80,90}, {"Linda",87,76,70},{"Peter",90,100,99}}; for(i=0;i<4;i++) {  GetAverage(______2______);        //  st + i } printf("Name\tMath\tEnglish\tCompu\tAverage\n"); for(i=0;i<4;i++) {  printf("%s\t%d\t%d\t%d\t%d\n",st[i].name,st[i].math,st[i].english, st[i].computer,st[i].average); } } 输入m、n(要求输入数均大于0)。输出它们的最大公约数。 #include<stdio.h> void main() {  int  m, n, k; while ( scanf("%d%d", &m, &n), ______1______ );    //  m<=0||n<=0 for (___2___ ; n%k!=0 || m%k!=0 ; k--) ;            //  k=m>n?n:m printf("%d\n", k); } 求出a中各相邻两个元素的和,并将这些和存放在数组b中,按每行3个元素的形式输出。例如:b[1]=a[0]+a[1],……,b[9]=a[8]+a[9]。 #include <stdio.h> void main() {  int a[10],b[10],i; printf("\nInput 10 numbers:  "); for (i=0; i<10;i++)                  /* 数组输入 */ scanf("%d", &a[i]); for (i=1; i<10; i++) b[i]=______1______;    /* 计算b数组中的元素 */  // a[i-1]+a[i] for (i=1; i<10; i++) {  printf("%3d",b[i]); if (______2______)  printf("\n");  /* 每行打印3个数据 */  //  i%3= =0 } } 输入整数n(n>0),求m使得2的m次方小于或等于n,2的m+1次方大于或等于n。 #include <stdio.h> void main() {  int m=0,t=1,n; while( _____ 1 ________);      //  scanf(“%d”,&n), n<=0    // 逗号表达式 while(!(t<=n&&t*2>=n)){ _____ 2 _____                //  t=t*2; m++; } printf(“%d\n”,m);                                                 }
本文档为【计算机二级C语言题库之程序填空】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_471618
暂无简介~
格式:doc
大小:37KB
软件:Word
页数:0
分类:生活休闲
上传时间:2017-09-20
浏览量:43