您好,欢迎访问三七文档
试卷编号:10767所属语言:C语言试卷方案:TC_150604083824试卷总分:570分共有题型:1种一、程序设计共57题(共计570分)第1题(10.0分)题号:374难度:易第2章/*------------------------------------------------【程序设计】--------------------------------------------------功能:编写函数实现两个数据的交换,在主函数中输入任意三个数据,调用函数对这三个数据从大到小排序。------------------------------------------------*/#includestdio.hvoidwwjt();voidswap(int*a,int*b){/**********Program**********//**********End**********/}main(){intx,y,z;scanf(%d%d%d,&x,&y,&z);if(xy)swap(&x,&y);if(xz)swap(&x,&z);if(yz)swap(&y,&z);printf(%3d%3d%3d,x,y,z);wwjt();}voidwwjt(){FILE*IN,*OUT;intm,n;inti[2];IN=fopen(in.dat,r);if(IN==NULL){printf(ReadFILEError);}OUT=fopen(out.dat,w);if(OUT==NULL){printf(WriteFILEError);}for(n=0;n3;n++){for(m=0;m2;m++){fscanf(IN,%d,&i[m]);}swap(&i[0],&i[1]);fprintf(OUT,%d\n,i[0]);fprintf(OUT,%d\n,i[1]);}fclose(IN);fclose(OUT);}答案:----------------------intk;k=*a;*a=*b;*b=k;----------------------第2题(10.0分)题号:381难度:易第2章/*------------------------------------------------【程序设计】--------------------------------------------------功能:求一批数中小于平均值的数的个数。------------------------------------------------*/#includestdio.hvoidwwjt();intaverage_num(inta[],intn){/**********Program**********//**********End**********/}main(){intn,a[100],i,num;scanf(%d,&n);for(i=0;in;i++)scanf(%d,&a[i]);num=average_num(a,n);printf(thenumis:%d\n,num);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;inti[10];into;IN=fopen(in.dat,r);if(IN==NULL){printf(ReadFILEError);}OUT=fopen(out.dat,w);if(OUT==NULL){printf(WriteFILEError);}for(n=0;n5;n++){fscanf(IN,%d,&i[n]);}o=average_num(i,5);fprintf(OUT,%d\n,o);fclose(IN);fclose(OUT);}答案:----------------------inti,sum=0,k=0;doubleaverage;for(i=0;in;i++)sum=sum+a[i];average=sum*1.0/n;for(i=0;in;i++)if(averagea[i])k++;return(k);----------------------第3题(10.0分)题号:406难度:易第2章/*------------------------------------------------【程序设计】--------------------------------------------------功能:编写函数fun求1000以内所有7的倍数之和。------------------------------------------------*/#defineN1000#includestdio.hvoidwwjt();intfun(intm){/**********Program**********//**********End**********/}voidmain(){intsum;sum=fun(7);printf(%d以内所有%d的倍数之和为:%d\n,N,7,sum);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;inti[10];into;OUT=fopen(out.dat,w);if(OUT==NULL){printf(WriteFILEError);}o=fun(6);fprintf(OUT,%d\n,o);fclose(IN);fclose(OUT);}答案:----------------------ints=0,i;for(i=1;iN;i++)if(i%m==0)s+=i;returns;----------------------第4题(10.0分)题号:324难度:易第2章/*------------------------------------------------【程序设计】--------------------------------------------------功能:能计算从1开始到n的自然数中偶数的平方的和,n由键盘输入,并在main()函数中输出。(n是偶数)------------------------------------------------*/#includestdio.hvoidwwjt();intfun(intn){/**********Program**********//**********End**********/}main(){intm;printf(Enterm:);scanf(%d,&m);printf(\nTheresultis%d\n,fun(m));wwjt();}voidwwjt(){FILE*IN,*OUT;intt;into;intc;IN=fopen(in.dat,r);if(IN==NULL){printf(ReadFILEError);}OUT=fopen(out.dat,w);if(OUT==NULL){printf(WriteFILEError);}for(c=1;c=5;c++){fscanf(IN,%d,&t);o=fun(t);fprintf(OUT,%d\n,o);}fclose(IN);fclose(OUT);}答案:----------------------intsum,i;sum=0;for(i=2;i=n;i=i+2){sum=sum+i*i;}return(sum);----------------------第5题(10.0分)题号:2难度:中第1章/*-------------------------------------------------------【程序设计】---------------------------------------------------------题目:写程序求1-3+5-7+…-99+101的值要求:使用程序中定义的变量-------------------------------------------------------*/#includestdio.hvoidwwjt();//函数功能:求1-3+5-7+…-+n的值intfun(intn){inti,s=0,f=1;//i定义为循环变量,s为1-3+5-7+…-n的值/**********Program**********//**********End**********/returns;}main(){printf(%d,fun(101));wwjt();}voidwwjt(){FILE*IN,*OUT;inti,n;IN=fopen(in.dat,r);if(IN==NULL){printf(PleaseVerifyTheCurrentDir..ItMayBeChanged);}OUT=fopen(out.dat,w);if(OUT==NULL){printf(PleaseVerifyTheCurrentDir..ItMayBeChanged);}for(i=0;i5;i++){fscanf(IN,%i,&n);fprintf(OUT,%ld\n,fun(n));}fclose(IN);fclose(OUT);}答案:for(i=1;i=n;i+=2){s=s+i*f;f=-f;}第6题(10.0分)题号:357难度:易第2章/*------------------------------------------------【程序设计】--------------------------------------------------功能:根据整型形参m,计算如下公式的值:y=1/5+1/6+1/7+1/8+1/9+1/10...+1/(m+5)例如:若m=9,则应输出:1.168229------------------------------------------------*/#includestdio.hvoidwwjt();doublefun(intm){/**********Program**********//**********End**********/}main(){intn;printf(Entern:);scanf(%d,&n);printf(\nTheresultis%1f\n,fun(n));wwjt();}voidwwjt(){FILE*IN,*OUT;inti;intt;doubleo;IN=fopen(in.dat,r);if(IN==NULL){printf(ReadFILEError);}OUT=fopen(out.dat,w);if(OUT==NULL){printf(WriteFILEError);}for(i=0;i5;i++){fscanf(IN,%d,&t);o=fun(t);fprintf(OUT,%f\n,o);}fclose(IN);fclose(OUT);}答案:----------------------doubley=0;inti;for(i=0;i=m;i++){y+=1.0/(i+5);}return(y);----------------------第7题(10.0分)题号:392难度:中第2章/*------------------------------------------------【程序设计】--------------------------------------------------功能:求一批数中最大值和最小值的积。------------------------------------------------*/#defineN30#includestdlib.h#includestdio.hvoidwwjt();intmax_min(inta[],intn){/**********Program**********//*
本文标题:C语言期末复习试题
链接地址:https://www.777doc.com/doc-7028888 .html