计算机二级c语言上机 - 程序填空题(4)

2019-05-24 08:04

void fun (char *s, char *t) { int i,j,sl;

/************found************/ sl = ___1___(s);

for (i=0, j=0; i

{ t[2*j] = s[i+1]; t[2*j +1] = s[i+1];

j++; }

t[2*j] = s[i]; t[2*j +1] = s[i]; /************found************/ ___2___; } t[2*sl] = '\\0';} main()

{ char s[100], t[100];

printf(\/************found************/ fun(___3___);

printf(\

第一空:strlen 第二空:j=j+1 第三空:s,t

58.给定程序的功能是根据公式求P的值,结果由函数值带回。m与n为两个正整数且要求m>n。

P?m!n!(m?n)!

例如:m=11,n=4时,运行结果为

330.000000。

#include long jc(int m)

{ long s=1; int i ;

/**************found**************/ for(i=1;i<=m;i++) s=___1___ ; return s;}

float fun(int m, int n) { float p;

/**************found**************/ p=1.0*jc(m)/jc(n)/jc(___2___) ;

/**************found**************/ ___3___;}

main(){ printf(\第一空:s*i 第二空:m-n 第三空:return p

59.给定程序的功能是把a数组中的n个数,和b数组中逆序的n个数一一对应相乘求平方,结果存在c数组中。例如:当a数组中的值是:1、3、5、7、8,b数组中的值是:2、3、4、5、8,c中存放的数据是:64、225、400、441、256。 #include

void fun(int a[], int b[], int c[], int n) { int i;

for (i=0; i

/**************found**************/ _1___ = (a[i] * b[n-1-i]) *(a[i] * b[n-1-i]);} main()

{ int i, a[100]={1,3,5,7,8},

b[100]={2,3,4,5,8}, c[100];

/**************found**************/ fun(___2___, 5);

printf(\

/**************found**************/

for (i=0; i<5; i++) printf(\ printf(\

第一空:c[i] 第二空:a,b,c 第三空:c[i]

60.给定程序的功能是根据公式计算S,计算结果通过形参指针sn传回;n通过形参传入。

Sn?11?13?15?17???12n?1例如,若n的值

为15时,输出结果是:S=0.769788 N=15。

#include

void fun(float *sn, int n)

{/**************found**************/ int i,j=___1___; float s=0.0;

for(i=0;i<=n;i++) { s=s+j*1.0/(2*i+1); j*=-1; }

/**************found**************/ ___2___=s;}

main(){ int n=15; float s;

/**************found**************/ fun(___3___);

printf(\第一空:1 第二空:*sn 第三空:&s,n

61.给定程序的功能是把s 串中所有的字母改写该字母的下一个字母,字母z改写成字母a。大写字母仍为大写字母,小写字母仍为小写字母,其它字符不变。 #include #include #include #define N 81 fun ( char *s )

{/**************found**************/ char *p = ___1___ ; while(*p) {

/**************found**************/ if(*p == 'Z') *p = ___2___ ;

/**************found**************/ else if(*p == 'z') *p = ___3___ ; else if(isalpha(*p)) *p = (*p) + 1 ; p++ ; }}

main( ){ char a[N];

printf ( \ \

printf ( \ \ fun ( a );

printf ( \ \ puts ( a );}

第一空:s 第二空:?A?或65 第三空:?a?或97

62.给定程序中,函数fun的功能是:有N×N矩阵,根据给定的m(m

个位置,左边置为0。例如,N=3,m=2,则下列矩阵 1 2 3 程序执行结果为 0 0 1 4 5 6 0 0 4 7 8 9 0 0 7 #include #define N 4

void fun(int (*t)[N], int m) { int i, j;

/**********found**********/ for(i=0; i=0; j--) /**********found**********/ t[i][j+___2___ ]=t[i][j]; /**********found**********/ for(j=0; j<___3___; j++) t[i][j]=0; }} main()

{ int t[][N]={21,12,13,24,25,16,47,

38,29,11,32,54,42,21,33,10}, i, j, m; printf(\ for(i=0; i

printf(\ \ printf(\ }

printf(\ \scanf(\ fun(t,m);

printf(\ for(i=0; i

printf(\ \ printf(\ }}

第一空:i++ 第二空:m 第三空:m

63.给定程序的功能是建立一个带有头结点的单向链表,并用随机函数为各结点赋值。函数fun的功能查找结点数据域最大值,并且作为函数值返回。 #include #include typedef struct aa

{ int data; struct aa *next; }NODE; int fun(NODE *h) { int max = 0 ;

/***********found**********/ ___1___ *p; p=h->next;

/***********found**********/ max=___2___ while(p)

{ if(p->data>max) max=p->data;

/***********found**********/ ___3___ } return max;}

NODE *creatlink(int n) { NODE *h, *p, *s, *q; int i, x;

h=p=(NODE *)malloc(sizeof(NODE)); for(i=1; i<=n; i++)

{ s=(NODE *)malloc(sizeof(NODE)); s->data=rand(); s->next=p->next; p->next=s; p=p->next; } p->next=NULL; return h;}

outlink(NODE *h, FILE *pf) { NODE *p; p = h->next;

fprintf(pf ,\ LIST :\\n\\n HEAD \ while(p)

{ fprintf(pf ,\ fprintf (pf,\}

outresult(int s, FILE *pf)

{fprintf(pf,\ %d\\n\main()

{ NODE *head; int even; head=creatlink(12); head->data=9000; outlink(head , stdout); even=fun(head);

printf(\ result :\\n\ outresult(even, stdout);}

第一空:NODE 第二空:p->data 第三空:p=p->next 64.给定程序的功能是把一个字符串的字符复制到另外一个字符串中。

void cpystr(char *ps,char *pd) { while(*ps!='\\0') { *pd=*ps; pd++;

/******found******/ ___1___; } /******found******/ *pd=___2___;} main(){

char *pa=\ pb=b;

/******found******/ ___3___

printf(\ return 0;}

第一空:ps++ 第二空:?\\0?或0 第三空:strcpy(pa,pb); 65.给定程序的功能是:从键盘输入一个字符串(长度不超过80个字符),依次扫描字符串中的小写字母o,每次将小写字母o的左右字符串部分作交叉换位,即左边字符串移到小写字母o的右边,而原先右边的则返之。并把小写字母o删除,依次直至小写字母o处理完,之后已处理的字符串出到屏幕。例如:输入字符串为:”123oabco98”,处理后输出为”98123abc”。 #include

#include void main()

{int i=0,j=0,sj=0,bs; char ch[80]; char *s,*f;

printf(\ scanf(\ while (ch[i]!='\\0') {

/******found******/ if ___1___ {sj++;}

/******found******/ ___2___; } for (i=0;i

strcat(f,s); strcpy(ch,f); }

printf(\

第一空:(ch[i]==?o?) 第二空:i++ 第三空:break 66.给定程序的功能是:从键盘输入一个字符串(长度不超80个字符),依次扫描字符串的小写字母o,每次将小写字母o左侧所有小写字母转换为大写字母,大写字母转换为小写字母。并把小写字母o删除,依次直至小写字母o处理完,之后把已处理的字符串输出到屏幕。例如:输入字符串为”aA1BoCao”,处理后输出为”aA1BcA”。输入字符串”aAobC”,输出为”AabC”。 #include #include void main()

{int i=0,j=0,nulin,sj=0,m; char ch[80];

printf(\ scanf(\ while (ch[i]!='\\0') { if (ch[i]=='o') sj++; i++; } for (i=0;i

/***************found***************/ ___1___;

for (m=0;m

{if (ch[m]>='a' && ch[m]<='z') ch[m]=ch[m]-32; /***************found***************/ ___2___

if (ch[m]>='A' && ch[m]<='Z') ch[m]=ch[m]+32; } if (m>=j)

ch[m]=ch[m+1]; }

/***************found***************/ ___3___;}

printf(\

第一空:nulin=strlen(ch); 第二空:else 第三空:ch[nulin-1]=?\\0?;

67. 给定函数countValue(int n),它的功能是:求n以内(不包括n)同时被3与7整除的所有自然数之和的平方根s,s作为函数返回值。主程序调用该函数输出n为1000时的函数值153.909064。 #include #include /******found******/

___1___ countValue(int n) { double xy=0.0; int i;

/******found******/ for(i=8;__2___;i++)

if(i%3==0&&i%7==0) xy+=i; xy=sqrt((double)xy); /******found******/ ___3___;} main()

{ printf(\

第一空:double 第二空:i #include

double countValue(int n) /******found******/ { ___1___xy=0.0; int i;

for(i=1;i

if(i==0&&i%7==0) /******found******/ ___2___; return xy;} main(){

/******found******/

printf(\

第一空:double 第二空:xy=xy+sqrt((double)i) 第三空:countValue(1000)

69.给定程序的功能分别求7个学生三门课程的平均成绩,在主程序中输出各学生平均成绩和最大平均成绩av。

#include #include

float fun(float a,float b,float c) { float sum,aver; sum=a+b+c;

/**********found************/ ___1___; return(aver);}

main(){ float a[7][3]={{80,90.5,81.5}, {70,69.8,90.5}, {68,97,99.0}, {86.5,89,95}, {78,96,90}, {87.5,89,92}, {64.5,80,78}}; float av=0.0,b[7];int i; for (i=0;i<7;i++)

/**********found************/ {b[i]=___2___;

/**********found************/ if ___3___ av=b[i];} for (i=0;i<7;i++)

printf(\ printf(\

第一空:aver=sum/3.0 第二空:b[i]=fun(a[i][0],a[i][1],a[i][2]); 第三空:if(av

70.给定程序的功能是用递归法计算n!。用递归方法计算n!,可使用如下公式表示

┌1 (n=0,1) n!= ┤

└n×(n-1)!(n>1) #include long ref(int n) { long m;

if (n<0) printf(\/************found************/ else if (___1___) m=1;

/************found************/ else ___2___; return(m);}

main(){ int n; long y;

printf(\/************found************/ scanf(\ y=ref(n);

printf(\ return;} 第一空:(n==0||n==1)第二空:m=ref(n-1)*n 第三空:&n

71.给定程序的功能是求出数组中的最大数max及最大数的个数cnt数组xx中值能被3整除或能被7整除的算术平均值pj(保留职位小数),结果max,cnt,pj输出到屏幕。

#include #define N 20 void main() { int max;

int cnt,xx[N]={78,43,56,34,43,32,85, 43,46,10,90,34,90,3,52,61,42,89,90,54}; float pj;

long j=0; int I,k;

/*************found************/ ___1___

/*************found************/ for(___2___;I

/*************found************/ {if (xx[I]>max) ___3___;

if (xx[I]%3==0||xx[I]%7==0) {j+=xx[I];k++;} } for (I=0,cnt=0;I

printf(\max,cnt,pj);}??

第一空:max=xx[0];第二空: for(i=0,k=0;i

72.给定程序的功能是找出所有100以内(含100)满足I,I+4,I+10都是素数的整数I(I+10也以100以内)的个数cnt以及这些I之和sum。 #include int cnt,sum;

int isPrime(int number) { int i,tag=1;

if(number==1) return 0;

for(i=2;tag&&i<=number/2;i++)

/***************found***************/ if(___1___) tag=0; return tag;} void countValue()

{ int I,count=0,xx[30]; int j,k,m;

cnt=0; sum=0;

/***************found***************/ for(I=1;___2___;I++)

if(isPrime(I)) {xx[count]=I;count++;} for(I=0;I

if (isPrime(xx[I]+4)&&isPrime(xx[I]+10)) /***************found***************/ {___3___;}}

void main(){ cnt=sum=0;

countValue();printf(\ printf(\

第一空:number%i==0 第二空:I<90 第三空:cnt++;sum+=xx[I]

73.给定程序的功能是对从键盘输入的字符数组xx(不超过80个字符),按字符从大到小的顺序进行排序,排序后的结果存入字符串数组xx中。例如:输入:dAe,BfC.结果:fedCBA. #include void main()

{ char xx[80] ;

int numi,numj; char ch;

printf(\ scanf(\

for (numi=0;numi

/***************found***************/ for (numj=___1___;numj

/***************found***************/

___2___;

xx[numi]=xx[numj];

/***************found***************/

___3___;}

printf(\

第一空:numi+1 第二空:ch=xx[numi] 第三空:xx[numj]=ch

74.给定程序的功能是:对字符数组xx中字符按给定的替代关系对所有字符进行替代,仍存入数组xx的对应的位置上。替代关系:f(p)=p*11 mod 256(p是数组xx中某一个字符的ASCII值,f(p)是计算后新字符的ASCII值),如果原字符是大写字母或计算后f(p)值小于等于32, 则该字符不变,否则将f(p)所对应的字符进行替代。

#include #include void main() { char xx[80]; int i,j;

printf(\ scanf(\

/***************found***************/ for (i=0;___1___;i++)

if((('A'<=xx[i])&&(xx[i]<='Z'))|| (((xx[i]*11) % 256 )<=32))

/***************found***************/ ___2___ else

/***************found***************/ xx[i]=___3___;

printf(\

第一空:i

#include struct stu_list { int num;

char name[20]; char sex; float score;

}s[5]={{9801,\

{9802,\ {9803,\ {9804,\ {9805,\main() { int i,c=0;

float ave,sum=0; for (i=0;i<5;i++) {

/***************found***************/ sum+=___1___;

/***************found***************/ if (___2___) c+=1;}

printf(\

/***************found***************/ ___3___;

printf(\ return; } ?? 第一空:sum+=s[i].score 第二空:if(s[i].score<60) c+=1 第三空:ave=sum/5;

76.给定程序的功能是在三位整数(100至999)中寻找符合下面条件的整数,并依次从小到大存入数组b[]中;它既是完全平方数,又有两位数相同,例如144,676等。函数int jsValue(int n)判断参数是否满足该条件,如果满足该条件函数返回值为1,否则返回值为0。 #include int jsValue(int n) { int j,k=0;

int n1,n2,n3; j=10; while(j*j<=n) { if (n==j*j) { n1=n / 100;

/***************found***************/ n2=___1___; n3=n % 10; if(n1==n2||n1==n3||n2==n3) k=1; }

/***************found***************/ ___2___; } return k;} main()

{ int b[20],num,i;

for (i=100,num=0;i<=999;i++) if (jsValue(i)==1) { b[num]=i;

/***************found***************/ ___3___; } for (i=0;i

printf(\第一空:(n/10) 第二空:j++; 第三空:num++; 77.给定程序的功能是从键盘输入3行3列矩阵的各个元素,然后输出对角线元素之和。 #include int fun()

{ int a[3][3],sum; int i,j;

/***************found**************/ sum=___1___; for (i=0;i<3;i++) {for (j=0;j<3;j++)


计算机二级c语言上机 - 程序填空题(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:《统计学原理》习题集

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: