二级C语言上机题及答案(程序设计)

申明敬告: 本站不保证该用户上传的文档完整性,不预览、不比对内容而直接下载产生的反悔问题本站不予受理。

文档介绍

二级C语言上机题及答案(程序设计)

程序设计题一、程序设计共113题第1题题号:319------------------------------------------功能:判断m是否为素数。------------------------------------------#include"stdio.h"voidwwjt();intfun(intm){/**********Program**********//**********End**********/}main(){intm,k=0;for(m=100;m<200;m++)if(fun(m)){printf("%4d",m);k++;if(k%5==0)printf("n");}printf("k=%dn",k);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN,iOUT,i;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..ItMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..ItMayBeChanged");}for(i=0;i<10;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%dn",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------inti,k=1;if(m<=1)k=0;for(i=2;i#include#defineM3#defineN4voidwwjt();voidfun(inttt[M][N],intpp[N]){/**********Program**********//**********End**********/}main(){intt[M][N]={{22,45,56,30},{19,33,45,38},{20,22,66,40}};intp[N],i,j,k;printf("Theoriginaldatais:n");for(i=0;ipp[j])pp[j]=tt[i][j];}----------------------第3题题号:375------------------------------------------功能:从键盘上输入任意实数,求出其所对应的函数值。z=e的x次幂(x>10)z=log(x+3)(x>-3)z=sin(x)/((cos(x)+4)------------------------------------------#include#includevoidwwjt();doubley(floatx){/**********Program**********//**********End**********/}main(){floatx;scanf("%f",&x);printf("y=%fn",y(x));wwjt();}voidwwjt(){FILE*IN,*OUT;intn;floati;doubleo;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<10;n++){fscanf(IN,"%f",&i);o=y(i);fprintf(OUT,"%ldn",o);}fclose(IN);fclose(OUT);}答案:----------------------doublez;if(x>10)z=exp(x);elseif(x>-3)z=log(x+3);elsez=sin(x)/(cos(x)+4);return(z);----------------------第4题题号:334第35页共35页n程序设计题------------------------------------------功能:求给定正整数n以内的素数之积。(n<28)------------------------------------------#include#include"conio.h"voidwwjt();longfun(intn){/**********Program**********//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("nTheresultis%ldn",fun(m));wwjt();}voidwwjt(){FILE*IN,*OUT;intc;intt;longo;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,"%ldn",o);}fclose(IN);fclose(OUT);}答案:----------------------longi,k;longs=1;for(i=2;i<=n;i++){for(k=2;k#include"conio.h"voidwwjt();longintfun(intn){/**********Program**********//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("nTheresultis%ldn",fun(m));wwjt();}voidwwjt(){FILE*IN,*OUT;ints;intt;longinto;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(s=1;s<=5;s++){fscanf(IN,"%d",&t);o=fun(t);fprintf(OUT,"%ldn",o);}fclose(IN);fclose(OUT);}答案:----------------------longs=1,i;for(i=2;i<=n;i++)if(n%i==0)s=s*i;returns;----------------------第6题题号:50------------------------------------------功能:求出菲波那契数列的前一项与后一项之比的极限的近似值。例如:当误差为0.0001时,函数值为0.618056。------------------------------------------#include#include"math.h"voidwwjt();floatfun(){/**********Program**********//**********End**********/}main(){printf("y=%fn",fun());wwjt();}voidwwjt(){FILE*IN,*OUT;floatfOUT;IN=fopen("19.IN","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("19.out","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}fOUT=fun();fprintf(OUT,"%fn",fOUT);fclose(IN);fclose(OUT);}答案:----------------------floatf1=1,f2=1,f3;floatr1=2,r2;do{r2=r1;r1=f1/f2;f3=f1+f2;f1=f2;f2=f3;}while(fabs(r1-r2)>1e-4);returnr1;----------------------第7题题号:394------------------------------------------功能:产生20个[30,120]上的随机整数放入二维数组a[5][4]中,求其中的最小值。------------------------------------------#include"stdlib.h"#includevoidwwjt();intamin(inta[5][4]){/**********Program**********//**********End**********/}第35页共35页n程序设计题main(){inta[5][4],i,j;for(i=0;i<5;i++)for(j=0;j<4;j++)a[i][j]=random(120-30+1)+30;for(i=0;i<5;i++){for(j=0;j<4;j++)printf("%5d",a[i][j]);printf("n");}printf("min=%dn",amin(a));wwjt();}voidwwjt(){FILE*IN,*OUT;intm,n;inti[5][4];into;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(m=0;m<5;m++)for(n=0;n<4;n++){fscanf(IN,"%d",&i[m][n]);}o=amin(i);fprintf(OUT,"%dn",o);fclose(IN);fclose(OUT);}答案:----------------------inti,j,s;s=a[0][0];for(i=0;i<5;i++)for(j=0;j<4;j++)if(s>a[i][j])s=a[i][j];return(s);----------------------第8题题号:337------------------------------------------功能:将两个两位数的正整数a、b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的百位和个位上,b数的十位和个位数依次放在c数的十位和千位上。例如:当a=45,b=12。调用该函数后,c=2415。------------------------------------------#includevoidwwjt();voidfun(inta,intb,long*c){/**********Program**********//**********End**********/}main(){inta,b;longc;printf("inputa,b:");scanf("%d%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ldn",c);wwjt();}voidwwjt(){FILE*rf,*wf;inti,a,b;longc;rf=fopen("in.dat","r");wf=fopen("out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%d,%d",&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ldn",a,b,c);}fclose(rf);fclose(wf);}答案:----------------------*c=a/10*100+a%10+b/10*10+b%10*1000;----------------------第9题题号:388------------------------------------------功能:编写函数判断一个整数能否同时被3和5整除,若能则返回值为1,否则为0。调用该函数求出15~300之间能同时被3和5整除的数的个数。------------------------------------------#includevoidwwjt();intsum(intn){/**********Program**********//**********End**********/}main(){inti,s=0;for(i=15;i<=300;i++)if(sum(i)==1)s=s+1;printf("s=%dn",s);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;inti[12];into;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<5;n++){fscanf(IN,"%d",&i[n]);}for(n=0;n<5;n++){o=sum(i[n]);fprintf(OUT,"%dn",o);}fclose(IN);fclose(OUT);}答案:----------------------if(n%3==0&&n%5==0)return(1);return(0);----------------------第10题题号:16------------------------------------------功能:编写函数fun求1!+2!+3!+……+n!的和,在main函数中由键盘输入n值,并输出运算结果。请编写fun函数。例如:若n值为5,则结果为153。------------------------------------------#includevoidwwjt();longintfun(intn){/**********Program**********//**********End**********/}main(){intn;longintresult;scanf("%d",&n);result=fun(n);printf("%ldn",result);wwjt();}voidwwjt(){FILE*IN,*OUT;inti;intiIN;longintiOUT;IN=fopen("in.dat","r");if(IN==NULL)第35页共35页n程序设计题{printf("PleaseVerifyTheCurrerntDir..ItMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..ItMayBeChanged");}for(i=0;i<10;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%ldn",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------inti;floatf=1,s=0;for(i=1;i<=n;i++){f=f*i;s=s+f;}returns;----------------------第11题题号:329------------------------------------------功能:对某一正数的值保留2位小数,并对第三位进行四舍五入。------------------------------------------#include#include"conio.h"voidwwjt();doublefun(floath){/**********Program**********//**********End**********/}main(){floatm;printf("Enterm:");scanf("%f",&m);printf("nTheresultis%8.2fn",fun(m));wwjt();}voidwwjt(){FILE*IN,*OUT;ints;floatt;doubleo;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(s=1;s<=5;s++){fscanf(IN,"%f",&t);o=fun(t);fprintf(OUT,"%8.2fn",o);}fclose(IN);fclose(OUT);}答案:----------------------inti;i=(int)(h*1000)%10;if(i>=5)return(int)(h*100+1)/100.0;elsereturn(int)(h*100)/100.0;----------------------第12题题号:410------------------------------------------功能:编写函数fun将一个数组中的值按逆序存放,并在main()函数中输出。例如:原来存顺序为8,6,5,4,1。要求改为:1,4,5,6,8。------------------------------------------#include#defineN5voidwwjt();intfun(intarr[],intn){/**********Program**********//**********End**********/}main(){inta[N]={8,6,5,4,1},i;for(i=0;ivoidwwjt();intfun(intn){/**********Program**********//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("nTheresultis%dn",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");}第35页共35页n程序设计题for(c=1;c<=5;c++){fscanf(IN,"%d",&t);o=fun(t);fprintf(OUT,"%dn",o);}fclose(IN);fclose(OUT);}答案:----------------------intsum,i;sum=0;for(i=1;i<=n;i++){sum=sum+i;}return(sum);----------------------第14题题号:507------------------------------------------功能:编写函数fun求一个字符串的长度,在main函数中输入字符串,并输出其长度。------------------------------------------#includevoidwwjt();intfun(char*p1){/**********Program**********//**********End**********/}main(){char*p,a[20];intlen;p=a;printf("pleaseinputastring:n");gets(p);len=fun(p);printf("Thestring'slengthis:%dn",len);wwjt();}voidwwjt(){FILE*IN,*OUT;char*pIN,sin[20];intiOUT,i;pIN=sin;IN=fopen("3.IN","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("3.out","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<10;i++){fscanf(IN,"%s",pIN);iOUT=fun(pIN);fprintf(OUT,"%dn",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------char*p;intn=0;p=p1;while(*p++)n++;returnn;----------------------第15题题号:44------------------------------------------功能:求出二维数组周边元素之和,作为函数值返回。二维数组的值在主函数中赋予。------------------------------------------#defineM4#defineN5#includevoidwwjt();intfun(inta[M][N]){/**********Program**********//**********End**********/}main(){inta[M][N]={{1,3,5,7,9},{2,4,6,8,10},{2,3,4,5,6},{4,5,6,7,8}};inty;y=fun(a);printf("s=%dn",y);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN[M][N],iOUT;inti,j,k;IN=fopen("14.IN","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("14.out","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(k=0;k<10;k++){for(i=0;ivoidwwjt();intfun(intn){/**********Program**********//**********End**********/}main(){intk;k=fun(1234);printf("k=%dn",k);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN,iOUT,i;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%dn",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------intd,s=0;第35页共35页n程序设计题while(n>0){d=n%10;s+=d*d*d;n/=10;}returns;----------------------第17题题号:339------------------------------------------功能:判断整数x是否是同构数。若是同构数,函数返回1;否则返回0。x的值由主函数从键盘读入,要求不大于100。说明:所谓“同构数”是指这样的数,这个数出现在它的平方数的右边。例如:输入整数5,5的平方数是25,5是25中右侧的数,所以5是同构数。------------------------------------------#includevoidwwjt();intfun(intx){/**********Program**********//**********End**********/}main(){intx,y;printf("nPleaseenteraintegernumbers:");scanf("%d",&x);if(x>100){printf("dataerror!n");exit(0);}y=fun(x);if(y)printf("%dYESn",x);elseprintf("%dNOn",x);wwjt();}voidwwjt(){FILE*IN,*OUT;intn,t;into;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(t=0;t<5;t++){fscanf(IN,"%d",&n);o=fun(n);fprintf(OUT,"%dn",o);}fclose(IN);fclose(OUT);}答案:----------------------intk;k=x*x;if((k%10==x)||(k%100==x))return1;elsereturn0;----------------------第18题题号:331------------------------------------------功能:找出一个大于给定整数且紧随这个整数的素数,并作为函数值返回。------------------------------------------#include#include"conio.h"voidwwjt();intfun(intn){/**********Program**********//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("nTheresultis%dn",fun(m));wwjt();}voidwwjt(){FILE*IN,*OUT;ints;intt;into;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(s=1;s<=5;s++){fscanf(IN,"%d",&t);o=fun(t);fprintf(OUT,"%dn",o);}fclose(IN);fclose(OUT);}答案:----------------------inti,k;for(i=n+1;;i++){for(k=2;kvoidwwjt();intRow,Col;intfun(intarray[N][M]){/**********Program**********//**********End**********/}main(){inta[N][M],i,j,max;printf("inputaarray:");for(i=0;i#defineVSIZE20voidwwjt();intvector[VSIZE];intfun(intlist[],intsize){/**********Program**********//**********End**********/}main(){inti;for(i=0;i#include#includevoidwwjt();voidfun(char*s,intnum){/**********Program**********//**********End**********/}main(){chars[10];printf("输入8个字符的字符串:");gets(s);fun(s,8);printf("n%s",s);wwjt();}voidwwjt(){inti;chara[100];FILE*rf,*wf;rf=fopen("in.dat","r");wf=fopen("out.dat","w");for(i=0;i<3;i++){fscanf(rf,"%s",&a);fun(a,8);fprintf(wf,"%s",a);fprintf(wf,"n");}fclose(rf);fclose(wf);}答案:----------------------inti,j;chart;for(i=0;ivoidwwjt();floatfun(floatx){/**********Program**********//**********End**********/}main(){floatx,f;printf("inputx=");scanf("%f",&x);f=fun(x);printf("x=%f,f(x)=%fn",x,f);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;floati;floato;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<10;n++){fscanf(IN,"%f",&i);o=fun(i);fprintf(OUT,"%fn",o);}fclose(IN);第35页共35页n程序设计题fclose(OUT);}答案:----------------------floaty;if(x<0&&x!=-3.0)y=x*x+x+6;elseif(x>=0&&x<10.0&&x!=2.0&&x!=3.0)y=x*x-5*x+6;elsey=x*x-x-1;returny;第23题题号:338------------------------------------------功能:编写程序,实现矩阵(3行3列)的转置(即行列互换)例如:输入下面的矩阵:100200300400500600700800900程序输出:100400700200500800300600900------------------------------------------#includevoidwwjt();intfun(intarray[3][3]){/**********Program**********//**********End**********/}main(){inti,j;intarray[3][3]={{100,200,300},{400,500,600},{700,800,900}};for(i=0;i<3;i++){for(j=0;j<3;j++)printf("%7d",array[i][j]);printf("n");}fun(array);printf("Convertedarray:n");for(i=0;i<3;i++){for(j=0;j<3;j++)printf("%7d",array[i][j]);printf("n");}wwjt();}voidwwjt(){inti,j,array[3][3];FILE*rf,*wf;rf=fopen("in.dat","r");wf=fopen("out.dat","w");for(i=0;i<3;i++)for(j=0;j<3;j++)fscanf(rf,"%d",&array[i][j]);fun(array);for(i=0;i<3;i++){for(j=0;j<3;j++)fprintf(wf,"%7d",array[i][j]);fprintf(wf,"n");}fclose(rf);fclose(wf);}答案:----------------------inti,j,t;for(i=0;i<3;i++)for(j=0;jvoidwwjt();intmax_min(inta[],intn){/**********Program**********//**********End**********/}main(){inta[N],i,k;for(i=0;imax)max=a[i];elseif(a[i]voidwwjt();longintfun(intd,intn){/**********Program**********//**********End**********/}main(){intd,n;longsum,fun();printf("d=");scanf("%d",&d);printf("n=");scanf("%d",&n);sum=fun(d,n);printf("sum=%ldn",sum);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;inti[2];longo;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<2;n++)第35页共35页n程序设计题{fscanf(IN,"%d",&i[n]);}o=fun(i[0],i[1]);fprintf(OUT,"%ldn",o);fclose(IN);fclose(OUT);}答案:----------------------longints=0,t=0;inti;for(i=1;i<=n;i++){t=t+d;s=s+t;d=d*10;}returns;----------------------第26题题号:395------------------------------------------功能:求n阶方阵主、副对角线上的元素之积。------------------------------------------#defineN4#include"stdlib.h"#includevoidwwjt();floatmul(intarr[][N]){/**********Program**********//**********End**********/}main(){inta[N][N],i,j;for(i=0;ivoidwwjt();fun(chars[],charc){/**********Program**********//**********End**********/}main(){staticcharstr[]="turbocandborlandc++";charc='a';fun(str,c);printf("str=%sn",str);wwjt();}voidwwjt(){FILE*IN,*OUT;charsin[80],cIN;inti;IN=fopen("13.IN","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("13.out","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<10;i++){fscanf(IN,"%s",sin);cIN=getc(IN);cIN=getc(IN);fun(sin,cIN);fprintf(OUT,"%sn",sin);}fclose(IN);fclose(OUT);}答案:----------------------inti,k=0;for(i=0;s[i]!='';i++)if(s[i]!=c)s[k++]=s[i];s[k]='';----------------------第28题题号:311------------------------------------------功能:计算n门课程的平均值,计算结果作为函数值返回。例如:若有5门课程的成绩是:92,76,69,58,88,则函数的值为76.600000。------------------------------------------#includevoidwwjt();floatfun(inta[],intn){/**********Program**********//**********End**********/}main(){inta[]={92,76,69,58,88};printf("y=%fn",fun(a,5));wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN[10],i,j;floatfOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(j=0;j<5;j++){for(i=0;i<5;i++)fscanf(IN,"%d",&iIN[i]);fOUT=fun(iIN,5);fprintf(OUT,"%fn",fOUT);}fclose(IN);fclose(OUT);}答案:----------------------第35页共35页n程序设计题inti;floaty=0;for(i=0;ivoidwwjt();longfun(longs,longt){/**********Program**********//**********End**********/}returnt;}main(){longs,t=0,m;printf("nPleaseenters:");scanf("%ld",&s);m=fun(s,t);printf("Theresultis:%ldn",m);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;longi,t=0,m;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<5;n++){fscanf(IN,"%ld",&i);m=fun(i,t);fprintf(OUT,"%ldn",m);}fclose(IN);fclose(OUT);}答案:----------------------longsl=10;s/=10;t=s%10;while(s>0){s=s/100;t=s%10*sl+t;sl=sl*10;-第30题题号:393------------------------------------------功能:编写函数求3!+6!+9!+12!+15+18!+21!。------------------------------------------#includevoidwwjt();floatsum(intn){/**********Program**********//**********End**********/}main(){printf("thissum=%en",sum(21));wwjt();}voidwwjt(){FILE*IN,*OUT;inti;floato;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}fscanf(IN,"%d",&i);o=sum(i);fprintf(OUT,"%fn",o);fclose(IN);fclose(OUT);}答案:----------------------inti,j;floatt,s=0;for(i=3;i<=n;i=i+3){t=1;for(j=1;j<=i;j++)t=t*j;s=s+t;}return(s);----------------------第31题题号:397------------------------------------------功能:编写函数fun(str,i,n),从字符串str中删除第i个字符开始的连续n个字符(注意:str[0]代表字符串的第一个字符)。------------------------------------------#includevoidwwjt();fun(charstr[],inti,intn){/**********Program**********//**********End**********/}main(){charstr[81];inti,n;printf("请输入字符串str的值:n");scanf("%s",str);printf("你输入的字符串str是:%sn",str);printf("请输入删除位置i和待删字符个数n的值:n");scanf("%d%d",&i,&n);while(i+n-1>strlen(str)){printf("删除位置i和待删字符个数n的值错!请重新输入i和n的值n");scanf("%d%d",&i,&n);}fun(str,i,n);printf("删除后的字符串str是:%sn",str);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;chari[200];charo[200];IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}fscanf(IN,"%s",i);fun(i,2,8);fprintf(OUT,"%sn",i);fclose(IN);fclose(OUT);}答案:----------------------while(str[i+n-1]){str[i-1]=str[i+n-1];i++;}str[i-1]='';----------------------第32题题号:29------------------------------------------功能:对任意输入的x,用下式计算并输出y的值。5x<10y=0x=10-5x>10------------------------------------------#includevoidwwjt();intfun(intn){/**********Program**********//**********End**********/}第35页共35页n程序设计题voidmain(){intx,y;printf("enterx:");scanf("%d",&x);y=fun(x);printf("x=%d,y=%dn",x,y);wwjt();}voidwwjt(){FILE*IN,*OUT;inti;intiIN;longintiOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%ldn",iOUT);}fclose(IN);fclose(OUT);}答案:intm;if(n<10)m=5;elseif(n==10)m=0;elsem=-5;returnm;或intm;if(n>=10)if(n>10)m=-5;elsem=0;elsem=5;returnm;第33题题号:323------------------------------------------功能:求1到w之间的奇数之和。(w是大于等于100小于等于1000的整数)------------------------------------------#include#include"conio.h"voidwwjt();longfun(intw){/**********Program**********//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("nTheresultis%ldn",fun(m));wwjt();}voidwwjt(){FILE*IN,*OUT;intc;intt;longo;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,"%ldn",o);}fclose(IN);fclose(OUT);}答案:----------------------longy=0;inti;for(i=1;i<=w;i++)if(i%2==1)y+=i;returny;----------------------第34题题号:312------------------------------------------功能:调用函数fun判断一个三位数是否"水仙花数"。在main函数中从键盘输入一个三位数,并输出判断结果。请编写fun函数。说明:所谓"水仙花数"是指一3位数,其各位数字立方和等于该数本身。例如:153是一个水仙花数,因为153=1+125+27。------------------------------------------#includevoidwwjt();intfun(intn){/**********Program**********//**********End**********/}main(){intn,flag;scanf("%d",&n);flag=fun(n);if(flag)printf("%d是水仙花数n",n);elseprintf("%d不是水仙花数n",n);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN,i;intiOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<10;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%dn",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------intbw,sw,gw;bw=n/100;sw=(n-bw*100)/10;gw=n%10;if(n==bw*bw*bw+sw*sw*sw+gw*gw*gw)return1;elsereturn0;----------------------第35题题号:378------------------------------------------功能:编写函数用冒泡排序法对数组中的数据进行从小到大的排序。------------------------------------------#include#includevoidwwjt();voidsort(inta[],intn){/**********Program**********//**********End**********/}main(){inta[16],i;for(i=0;i<16;i++)a[i]=random(30)+15;for(i=0;i<16;i++)printf("%3d",a[i]);printf("n-------------------n");sort(a,16);for(i=0;i<16;i++)printf("%3d",a[i]);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;第35页共35页n程序设计题inti[10];IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<10;n++){fscanf(IN,"%d",&i[n]);}sort(i,10);for(n=0;n<10;n++)fprintf(OUT,"%dn",i[n]);fclose(IN);fclose(OUT);}答案:----------------------inti,j,t;for(i=0;ia[j+1]){t=a[j];a[j]=a[j+1];a[j+1]=t;}第36题题号:504------------------------------------------功能:编写程序打印如图1所示图形。*************************要求:要求使用abs()。------------------------------------------#include#include"math.h"voidwwjt();voidfun(inti){intm,n;/**********Program**********//**********End**********/}main(){fun(3);}答案:for(m=-i;m<=i;m++){for(n=0;nvoidwwjt();main(){inti,j,s,a[3][3];for(i=0;i<3;i++){for(j=0;j<3;j++)scanf("%d",&a[i][j]);}s=fun(a);printf("Sum=%dn",s);wwjt();}intfun(inta[3][3]){/**********Program**********//**********End**********/}voidwwjt(){FILE*IN,*OUT;intm;intn;inti[3][3];into;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(m=0;m<3;m++){for(n=0;n<3;n++)fscanf(IN,"%d",&i[m][n]);}o=fun(i);{fprintf(OUT,"%dn",o);getch();}fclose(IN);fclose(OUT);}答案:----------------------intsum;inti,j;sum=0;for(i=0;i<3;i+=2)for(j=0;j<3;j++)sum=sum+a[i][j];returnsum;----------------------第38题题号:382------------------------------------------功能:给定n个数据,求最小值出现的位置(如果最小值出现多次,求出第一次出现的位置即可)。------------------------------------------#includevoidwwjt();intstation(ints[],intn){/**********Program**********//**********End**********/}main(){inta[100],n,i,t;scanf("%d",&n);for(i=0;i#defineM5voidwwjt();intfun(inta[M][M])第35页共35页n程序设计题{/**********Program**********//**********End**********/}main(){inta[M][M]={{1,3,5,7,9},{2,4,6,8,10},{2,3,4,5,6},{4,5,6,7,8},{1,3,4,5,6}};inty;y=fun(a);printf("s=%dn",y);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN[M][M],iOUT;inti,j;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}{for(i=0;ivoidwwjt();/*-全局变量,a用于保存字母个数、num用于保存数字个数b用于保存空格个数、other用于保存其他字符字数*/inta=0,num=0,b=0,other=0;voidcount(charc[]){/**********Program**********//**********End**********/}voidmain(){charch[80];printf("inputstring:");gets(ch);count(ch);printf("a=%dnum=%db=%dother=%dn",a,num,b,other);wwjt();}voidwwjt(){FILE*IN,*OUT;inti;charsin[80];IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){a=0;num=0;b=0;other=0;fscanf(IN,"%s",&sin);count(sin);fprintf(OUT,"%dn",a);fprintf(OUT,"%dn",num);fprintf(OUT,"%dn",b);fprintf(OUT,"%dn",other);}fclose(IN);fclose(OUT);}答案:inti;for(i=0;c[i]!='';i++)if((c[i]>='A'&&c[i]<='Z')||(c[i]>='a'&&c[i]<='z'))a=a+1;elseif(c[i]>='0'&&c[i]<='9')num=num+1;elseif(c[i]=='')b=b+1;elseother=other+1;第41题题号:387------------------------------------------功能:求一批数中最大值和最小值的差。------------------------------------------#defineN30#include"stdlib.h"#includevoidwwjt();intmax_min(inta[],intn){/**********Program**********//**********End**********/}main(){inta[N],i,k;for(i=0;imax)max=a[i];elseif(a[i]#defineVSIZE20voidwwjt();intvector[VSIZE];intfun(intlist[],intsize)第35页共35页n程序设计题{/**********Program**********//**********End**********/}main(){inti;for(i=0;ilist[i])min=i;returnmin;----------------------第43题题号:365------------------------------------------功能:求1到100之间的偶数之积。------------------------------------------#includevoidwwjt();doublefun(intm){/**********Program**********//**********End**********/}main(){printf("ji=%fn",fun(100));wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN,i;doubledOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%d",&iIN);dOUT=fun(iIN);fprintf(OUT,"%fn",dOUT);}fclose(IN);fclose(OUT);}答案:----------------------doubley=1;inti;for(i=1;i<=m;i++)if(i%2==0)y*=i;returny;----------------------第44题题号:366------------------------------------------功能:求一组数中大于平均值的数的个数。例如:给定的一组数为1,3,6,9,4,23,35,67,12,88时,函数值为3。------------------------------------------#includevoidwwjt();intfun(inta[],intn){/**********Program**********//**********End**********/}main(){inta[10]={1,3,6,9,4,23,35,67,12,88};inty;y=fun(a,10);printf("y=%dn",y);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN[10],iOUT,i,j;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(j=0;j<10;j++){for(i=0;i<10;i++)fscanf(IN,"%d",&iIN[i]);iOUT=fun(iIN,10);}fprintf(OUT,"%dn",iOUT);fclose(IN);fclose(OUT);}答案:----------------------inti,k=0;floats=0,ave;for(i=0;iave)k++;returnk;----------------------第45题题号:361------------------------------------------功能:编写程序,求矩阵(3行3列)与2的乘积例如:输入下面的矩阵:100200300400500600700800900程序输出:20040060080010001200140016001800------------------------------------------#includevoidwwjt();intfun(intarray[3][3]){/**********Program**********//**********End**********/}main(){inti,j;intarray[3][3]={{100,200,300},{400,500,600},{700,800,900}};for(i=0;i<3;i++){for(j=0;j<3;j++)printf("%7d",array[i][j]);printf("n");}fun(array);printf("Convertedarray:n");for(i=0;i<3;i++){for(j=0;j<3;j++)printf("%7d",array[i][j]);printf("n");}wwjt();}voidwwjt(){inti,j,array[3][3];FILE*rf,*wf;rf=fopen("in.dat","r");wf=fopen("out.dat","w");for(i=0;i<3;i++)第35页共35页n程序设计题for(j=0;j<3;j++)fscanf(rf,"%d",&array[i][j]);fun(array);for(i=0;i<3;i++){for(j=0;j<3;j++)fprintf(wf,"%7d",array[i][j]);fprintf(wf,"n");}fclose(rf);fclose(wf);}答案:----------------------inti,j;for(i=0;i<3;i++)for(j=0;j<3;j++)array[i][j]=array[i][j]*2;----------------------第46题题号:373------------------------------------------功能:用函数求fibonacci数列前n项的和。说明:fibonacci数列为数列的第一项值为1,第二项值也为1,从第三项开始,每一项均为其前面相邻两项的和。例如:当n=28时,运行结果:832039------------------------------------------#includevoidwwjt();longsum(longf1,longf2){/**********Program**********//**********End**********/}main(){longintf1=1,f2=1;printf("sum=%ldn",sum(f1,f2));wwjt();}voidwwjt(){FILE*IN,*OUT;intn;inti[2];longinto;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<2;n++)fscanf(IN,"%d",&i[n]);o=sum(i[0],i[1]);fprintf(OUT,"%ldn",o);fclose(IN);fclose(OUT);}答案:----------------------longf,k=f1+f2;inti;for(i=3;i<=28;i++){f=f1+f2;k=k+f;f1=f2;f2=f;}return(k);----------------------第47题题号:340------------------------------------------功能:编写一个函数,该函数可以统计一个长度为2的字符串在另一个字符串中出现的次数。例如:假定输入的字符串为:asdasasdfgasdaszx67asdmklo,字符串为:as,则应输出6。------------------------------------------#include#include#includevoidwwjt();intfun(char*str,char*substr){/**********Program**********//**********End**********/}main(){charstr[81],substr[3];intn;printf("输入主字符串:");gets(str);printf("输入子字符串:");gets(substr);puts(str);puts(substr);n=fun(str,substr);printf("n=%dn",n);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;chari[200];IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}fscanf(IN,"%s",i);n=fun(i,"as");fprintf(OUT,"%d",n);fclose(IN);fclose(OUT);}答案:----------------------inti,n=0;for(i=0;i<=strlen(str)-2;i++)if((str[i]==substr[0])&&(str[i+1]==substr[1]))n++;returnn;----------------------第48题题号:322------------------------------------------功能:判断一个整数w的各位数字平方之和能否被5整除可以被5整除则返回1,否则返回0。------------------------------------------#include#include"conio.h"voidwwjt();intfun(intw){/**********Program**********//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("nTheresultis%dn",fun(m));wwjt();}voidwwjt(){FILE*IN,*OUT;intc;intt;into;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,"%dn",o);}fclose(IN);fclose(OUT);}答案:----------------------intk,s=0;do{s=s+(w%10)*(w%10);w=w/10;}while(w!=0);if(s%5==0)k=1;elsek=0;return(k);----------------------第35页共35页n程序设计题第49题题号:343------------------------------------------功能:将两个两位数的正整数a、b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的个位和百位上,b数的十位和个位数依次放在c数的十位和千位上。例如:当a=45,b=12,调用该函数后,c=2514。#includevoidwwjt();voidfun(inta,intb,long*c){/**********Program**********//**********End**********/}main(){inta,b;longc;printf("inputa,b:");scanf("%d%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ldn",c);wwjt();}voidwwjt(){FILE*rf,*wf;inti,a,b;longc;rf=fopen("in.dat","r");wf=fopen("out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%d,%d",&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ldn",a,b,c);}fclose(rf);fclose(wf);}答案:----------------------*c=a/10+a%10*100+b/10*10+b%10*1000;----------------------第50题题号:411------------------------------------------功能:对任意输入的x,用下式计算并输出y的值。-1x<0y=0x=01x>0------------------------------------------#includevoidwwjt();intfun(intn){/**********Program**********//**********End**********/}voidmain(){intx,y;printf("enterx:");scanf("%d",&x);y=fun(x);printf("x=%d,y=%dn",x,y);wwjt();}voidwwjt(){FILE*IN,*OUT;inti;intiIN;longintiOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%ldn",iOUT);}fclose(IN);fclose(OUT);}答案:intm;if(n<0)m=-1;elseif(n==0)m=0;elsem=1;returnm;或intm;if(n>=0)if(n>0)m=1;elsem=0;elsem=-1;returnm;第51题题号:320------------------------------------------功能:在键盘上输入一个3行3列矩阵的各个元素的值(值为整数),然后输出主对角线元素的积,并在fun()函数中输出。------------------------------------------#includevoidwwjt();main(){inti,j,s,a[3][3];;for(i=0;i<3;i++){for(j=0;j<3;j++)scanf("%d",&a[i][j]);}s=fun(a);printf("Sum=%dn",s);wwjt();}intfun(inta[3][3]){/**********Program**********//**********End**********/}voidwwjt(){FILE*IN,*OUT;intm;intn;inti[3][3];into;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(m=0;m<3;m++){for(n=0;n<3;n++)fscanf(IN,"%d",&i[m][n]);}o=fun(i);{fprintf(OUT,"%dn",o);getch();}fclose(IN);fclose(OUT);}答案:----------------------intsum;inti,j;sum=1;for(i=0;i<3;i++)sum=sum*a[i][i];returnsum;----------------------第52题题号:318------------------------------------------功能:输入一个字符串,过滤此串,只保留串中的字母字符,并统计新生成串中包含的字母个数。例如:输入的字符串为ab234$df4,新生成的串为abdf。------------------------------------------#include#include#defineN80voidwwjt();fun(char*ptr){/**********Program**********//**********End**********/第35页共35页n程序设计题}main(){charstr[N];ints;printf("inputastring:");gets(str);printf("TheorigINalstringis:");puts(str);s=fun(str);printf("Thenewstringis:");puts(str);printf("Thereare%dcharINthenewstring.",s);wwjt();}voidwwjt(){FILE*IN,*OUT;charsin[N];intiOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}fscanf(IN,"%s",sin);iOUT=fun(sin);fprintf(OUT,"%d%sn",iOUT,sin);fclose(IN);fclose(OUT);}答案:----------------------inti,j;for(i=0,j=0;*(ptr+i)!='';i++)if(*(ptr+i)<='z'&&*(ptr+i)>='a'||*(ptr+i)<='Z'&&*(ptr+i)>='A'){*(ptr+j)=*(ptr+i);j++;}*(ptr+j)='';return(j);----------------------第53题题号:357------------------------------------------功能:根据整型形参m,计算如下公式的值:y=1/5+1/6+1/7+1/8+1/9+1/10...+1/(m+5)例如:若m=9,则应输出:1.168229------------------------------------------#includevoidwwjt();doublefun(intm){/**********Program**********//**********End**********/}main(){intn;printf("Entern:");scanf("%d",&n);printf("nTheresultis%1fn",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;i<5;i++){fscanf(IN,"%d",&t);o=fun(t);fprintf(OUT,"%fn",o);}fclose(IN);fclose(OUT);}答案:----------------------doubley=0;inti;for(i=0;i<=m;i++){y+=1.0/(i+5);}return(y);----------------------第54题题号:367------------------------------------------功能:找出一批正整数中的最大的偶数。------------------------------------------#includevoidwwjt();intfun(inta[],intn){/**********Program**********//**********End**********/}main(){inta[]={1,2,9,24,35,18},k;k=fun(a,6);printf("max=%dn",k);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN[10],iOUT,i,j;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(j=0;j<10;j++){for(i=0;i<10;i++)fscanf(IN,"%d",&iIN[i]);iOUT=fun(iIN,10);}fprintf(OUT,"%dn",iOUT);fclose(IN);fclose(OUT);}答案:----------------------inti,amax=-1;for(i=0;iamax)amax=a[i];returnamax;----------------------第55题题号:374------------------------------------------功能:编写函数实现两个数据的交换,在主函数中输入任意三个数据,调用函数对这三个数据从大到小排序。------------------------------------------#includevoidwwjt();voidswap(int*a,int*b){/**********Program**********//**********End**********/}main(){intx,y,z;scanf("%d%d%d",&x,&y,&z);if(x#include#includevoidwwjt();voidfun(char*s,intnum){/**********Program**********//**********End**********/}main(){chars[10];printf("输入7个字符的字符串:");gets(s);fun(s,7);printf("n%s",s);wwjt();}voidwwjt(){inti;chara[100];FILE*rf,*wf;rf=fopen("in.dat","r");wf=fopen("out.dat","w");for(i=0;i<3;i++){fscanf(rf,"%s",&a);fun(a,7);fprintf(wf,"%s",a);fprintf(wf,"n");}fclose(rf);fclose(wf);}答案:----------------------inti,j;chart;for(i=1;ivoidwwjt();doublefun(doublem){/**********Program**********//**********End**********/}voidmain(){doublec,f;printf("请输入一个华氏温度:");scanf("%f",&f);c=fun(f);printf("摄氏温度为:%5.2fn",c);wwjt();}voidwwjt(){FILE*IN,*OUT;inti;doubleiIN,iOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%f",&iIN);iOUT=fun(iIN);fprintf(OUT,"%fn",iOUT);}fclose(IN);fclose(OUT);}答案:floatn;n=(5.0/9.0)*(m-32);returnn;第58题题号:324【程序设计】------------------------------------------功能:能计算从1开始到n的自然数中偶数的平方的和,n由键盘输入,并在main()函数中输出。(n是偶数)#includevoidwwjt();intfun(intn){/**********Program**********//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("nTheresultis%dn",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,"%dn",o);}fclose(IN);fclose(OUT);}答案:----------------------intsum,i;sum=0;for(i=2;i<=n;i=i+2){sum=sum+i*i;}return(sum);----------------------第59题题号:53------------------------------------------功能:求一个四位数的各位数字的立方和------------------------------------------#includevoidwwjt();intfun(intn){/**********Program**********//**********End**********/}main(){intk;k=fun(1234);第35页共35页n程序设计题printf("k=%dn",k);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN,iOUT,i;IN=fopen("22.IN","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("22.out","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<10;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%dn",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------intd,k,s=0;while(n>0){d=n%10;s+=d*d*d;n/=10;}returns;----------------------第60题题号:389------------------------------------------功能:编写函数求表达式的和(n的值由主函数输入)。1-1/2+1/3-1/4+......+1/m例如:当n=20时,表达式的值为0.668771。------------------------------------------#includevoidwwjt();doublesum(intn){/**********Program**********//**********End**********/}main(){intn;scanf("%d",&n);printf("sum=%fn",sum(n));wwjt();}voidwwjt(){FILE*IN,*OUT;intn;inti[10];doubleo;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<5;n++)fscanf(IN,"%d",&i[n]);for(n=0;n<5;n++){o=sum(i[n]);fprintf(OUT,"%fn",o);}fclose(IN);fclose(OUT);}答案:----------------------floats=0;inti,k=1;for(i=1;i<=n;i++){s=s+k*1.0/i;k=-k;}return(s);----------------------第61题题号:350------------------------------------------功能:请编一个函数voidfun(inttt[M][N],intpp[N]),tt指向一个M行N列的二维数组,求出二维数组每列中最小元素,并依次放入pp所指一维数组中。二维数组中的数已在主函数中赋予。------------------------------------------#include#include#defineM3#defineN4voidwwjt();voidfun(inttt[M][N],intpp[N]){/**********Program**********//**********End**********/}main(){intt[M][N]={{22,45,56,30},{19,33,45,38},{20,22,66,40}};intp[N],i,j,k;printf("Theoriginaldatais:n");for(i=0;i#include#defineMAX100voidwwjt();intfun(intlim,intaa[MAX]){/**********Program**********//**********End**********/}main(){intlimit,i,sum;intaa[MAX];printf("Pleaseinputainteger:");scanf("%d",&limit);sum=fun(limit,aa);for(i=0;ivoidwwjt();main(){floatfun();printf("无理数e的值是:%fn",fun());wwjt();}floatfun(){/**********Program**********//**********End**********/}voidwwjt(){FILE*IN,*OUT;floato;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}o=fun();fprintf(OUT,"%fn",o);fclose(IN);fclose(OUT);}答案:----------------------longintj;inti,k;doublee,jc;i=1;e=0.0;jc=1.0;while(jc>=0.000001){e=e+jc;j=1;for(k=1;k<=i;k++)j=j*k;jc=1.0/j;i++;}returne;----------------------第64题题号:346------------------------------------------功能:将从键盘上输入的每个单词的第一个字母转换为写字母,输入时各单词必须用空格隔开,用’.’结束输入。#include#include"string.h"voidwwjt();intfun(char*c,intstatus){/**********Program**********//**********End**********/}main(){intflag=1;charch;printf("请输入一字符串,用点号结束输入!n");do{ch=getchar();flag=fun(&ch,flag);putchar(ch);}while(ch!='.');printf("n");wwjt();}voidwwjt(){chars1[81],ch;unsignedinti,flag=1;FILE*rf,*wf;rf=fopen("in.dat","r");wf=fopen("out.dat","w");fgets(s1,80,rf);for(i=0;i='a')*c+='A'-'a';return0;}----------------------第65题题号:359------------------------------------------功能:实现两个整数的交换。例如:给a和b分别输入:60和65,输入为:a=65b=60------------------------------------------#include#includevoidwwjt();voidfun(int*a,int*b){/**********Program**********//**********End**********/}main(){inta,b;printf("Entera,b:");scanf("%d%d",&a,&b);fun(&a,&b);printf("a=%db=%dn",a,b);wwjt();}voidwwjt(){FILE*IN,*OUT;inta,b,n;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<5;n++){fscanf(IN,"%d%d",&a,&b);fun(&a,&b);fprintf(OUT,"a=%db=%dn",a,b);}fclose(IN);fclose(OUT);}答案:----------------------intt;t=*a;*a=*b;*b=t;第66题题号:386------------------------------------------第35页共35页n程序设计题功能:用函数求N个[10,60]上的整数中能被5整除的最大的数,如存在则返回这个最大值,如果不存在则返回0。------------------------------------------#defineN30#include"stdlib.h"#includevoidwwjt();intfind(intarr[],intn){intm=0;/**********Program**********//**********End**********/return(m);}main(){inta[N],i,k;for(i=0;im)m=arr[i];----------------------第67题题号:502------------------------------------------题目:用while语句求1~100的累计和。------------------------------------------#include/voidwwjt();intfun(intn){/**********Program**********//**********End**********/}voidmain(){intsum=0;sum=fun(100);printf("sum=%dn",sum);wwjt();}voidwwjt(){FILE*IN,*OUT;inti;intiIN,iOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%dn",iOUT);}fclose(IN);fclose(OUT);}答案:inti=1,sum=0;while(i<=n){sum=sum+i;i++;}returnsum;第68题题号:336------------------------------------------功能:从字符串中删除指定的字符。同一字母的大、小写按不同字符处理。例如:若程序执行时输入字符串为:turbocandborlandc++从键盘上输入字符:n,则输出后变为:turbocadborladc++,如果输入的字符在字符串中不存在,则字符串照原样输出。------------------------------------------#includevoidwwjt();intfun(chars[],intc){/**********Program**********//**********End**********/}main(){staticcharstr[]="turbocandborlandc++";charch;printf("原始字符串:%sn",str);printf("输入一个字符:");scanf("%c",&ch);fun(str,ch);printf("str[]=%sn",str);wwjt();}voidwwjt(){FILE*IN,*OUT;chari[200];charo[200];IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}fscanf(IN,"%s",i);fun(i,'n');fprintf(OUT,"%s",i);fclose(IN);fclose(OUT);}答案:----------------------char*q=s;for(;*q;q++)if(*q!=c)*(s++)=*q;*s=0;----------------------第69题题号:376------------------------------------------功能:从键盘上输入任意实数x,求出其所对应的函数值。z=(x-4)的二次幂(x>4)z=x的八次幂(x>-4)z=z=4/(x*(x+1))(x>-10)z=|x|+20(其他)------------------------------------------#include#includevoidwwjt();floaty(floatx){/**********Program**********//**********End**********/}main(){floatx;scanf("%f",&x);printf("y=%fn",y(x));wwjt();第35页共35页n程序设计题}voidwwjt(){FILE*IN,*OUT;intn;floati;floato;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<10;n++){fscanf(IN,"%f",&i);o=y(i);fprintf(OUT,"%fn",o);}fclose(IN);fclose(OUT);}答案:----------------------floatz;if(x>4)z=sqrt(x-4);elseif(x>-4)z=pow(x,8);elseif(x>-10)z=4/(x*(x+1));elsez=fabs(x)+20;return(z);----------------------第70题题号:341------------------------------------------功能:删除所有值为y的元素。数组元素中的值和y的值由主函数通过键盘输入。------------------------------------------#include#include#include#defineM20voidwwjt();voidfun(intbb[],int*n,inty){/**********Program**********//**********End**********/}main(){intaa[M],n,y,k;printf("nPleaseentern:");scanf("%d",&n);printf("nEnter%dpositivenumber:n",n);for(k=0;kvoidwwjt();intfun(inta[],intn){/**********Program**********//**********End**********/}main(){inta[]={1,2,9,24,35,18},k;k=fun(a,6);printf("max=%dn",k);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN[10],iOUT,i,j;IN=fopen("28.IN","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("28.out","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(j=0;j<10;j++){for(i=0;i<10;i++)fscanf(IN,"%d",&iIN[i]);iOUT=fun(iIN,10);fprintf(OUT,"%dn",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------inti,amax=-1;for(i=0;iamax)amax=a[i];returnamax;第72题题号:379------------------------------------------功能:给定n个数据,求最大值出现的位置(如果最大值出现多次,求出第一次出现的位置即可)。------------------------------------------#includevoidwwjt();intstation(ints[],intn){/**********Program**********//**********End**********/}main(){inta[100],n,i,t;scanf("%d",&n);for(i=0;is[k])k=i;return(k+1);第73题题号:37------------------------------------------功能:输入2个学生3门课的成绩,计算学生成绩平均分课程平均分和最高分.例如:输入2名学生3门课的成绩分别为92,87,68,56,92,84则学生1平均分:82.33学生2平均分:77.33课程1平均分:74.00课程2平均分:89.50课程3平均分:76.00最高分为:92------------------------------------------#includevoidwwjt();/*定义全局变量*//*学生成绩平均分*/floatStuAgv[2];/*课程平均分*/floatCouAgv[3];/*所有学生的所有课程最高分*/floatMax=0;/*说明:需要在下面函数中把题干要求中的结果赋值到上面定义一变量*/voidfun(floatscore[2][3]){/**********Program**********//**********End**********/}voidmain(){inti,j;floatscore[2][3];printf("输入学生的成绩:");for(i=0;i<2;i++)for(j=0;j<3;j++)scanf("%f",&score[i][j]);printf("n输出学生的成绩:");for(i=0;i<2;i++){for(j=0;j<3;j++)printf("%.2f",score[i][j]);printf("n");}fun(score);for(i=0;i<2;i++)printf("第%d个学生的平均成绩是:%0.2fn",i+1,StuAgv[i]);for(j=0;j<3;j++)printf("第%d门课的平均成绩是:%0.2fn",j+1,CouAgv[j]);printf("所有分数中的最高分为:%.2fn",Max);wwjt();}voidwwjt(){FILE*IN,*OUT;floatiIN[2][3];inti,j;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<2;i++)for(j=0;j<3;j++)fscanf(IN,"%f",&iIN[i][j]);fun(iIN);for(i=0;i<2;i++)fprintf(OUT,"%.2fn",StuAgv[i]);for(j=0;j<3;j++)fprintf(OUT,"%.2fn",CouAgv[j]);fprintf(OUT,"%.2fn",Max);fclose(IN);fclose(OUT);return;}答案:inti,j;floatsum;for(i=0;i<2;i++)/*计算第i个学生平均分*/{sum=0;for(j=0;j<3;j++)sum=sum+score[i][j];StuAgv[i]=sum/3;}for(j=0;j<3;j++)/*计算第j门课的平均分*/{sum=0;for(i=0;i<2;i++)sum=sum+score[i][j];CouAgv[j]=sum/2;}Max=score[0][0];for(i=0;i<2;i++)for(j=0;j<3;j++)if(Max<=score[i][j]){Max=score[i][j];}return;第74题题号:33------------------------------------------功能:用do-while语句求1~100的累计和。------------------------------------------#includevoidwwjt();longintfun(intn){/**********Program**********//**********End**********/}voidmain(){inti=100;printf("1~100的累加和为:%ldn",fun(i));wwjt();}voidwwjt(){FILE*IN,*OUT;inti;intiIN;longintiOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%ldn",iOUT);}fclose(IN);fclose(OUT);}答案:inti=1,sum=0;do{sum=sum+i;i++;}while(i<=n);returnsum;第75题题号:372------------------------------------------题目:用函数求一个N阶方阵右下三角元素的和(包括副对角线上的元素)。------------------------------------------#include#include#defineN3voidwwjt();intsum(inta[][N]){/**********Program**********//**********End**********/第35页共35页n程序设计题}main(){inta[N][N],i,j;for(i=0;i#include"conio.h"voidwwjt();intfun(intw){/**********Program**********//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("nTheresultis%dn",fun(m));wwjt();}voidwwjt(){FILE*IN,*OUT;intc;intt;into;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,"%dn",o);}fclose(IN);fclose(OUT);}答案:----------------------intn=0;inti=1;while(w>10){n=n+i*(w%10);w/=10;i*=10;}returnn;----------------------第77题题号:369------------------------------------------功能:编写函数判断一个整数m的各位数字之和能否被7整除,可以被7整除则返回1,否则返回0。调用该函数找出100~200之间满足条件的所有数。------------------------------------------#includevoidwwjt();intsub(intm){/**********Program**********//**********End**********/}main(){inti;for(i=100;i<=200;i++)if(sub(i)==1)printf("%4d",i);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;n<10;n++){fscanf(IN,"%d",&i[n]);}for(n=0;n<10;n++){o=sub(i[n]);fprintf(OUT,"%dn",o);}fclose(IN);fclose(OUT);}答案:----------------------intk,s=0;do{s=s+m%10;m=m/10;}while(m!=0);if(s%7==0)k=1;elsek=0;return(k);----------------------第78题题号:332------------------------------------------功能:根据整型参数n,计算如图公式的值。------------------------------------------#include#include"conio.h"voidwwjt();doublefun(intn){/**********Program**********//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("nTheresultis%fn",fun(m));wwjt();}voidwwjt(){FILE*IN,*OUT;ints;intt;doubleo;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");第35页共35页n程序设计题if(OUT==NULL){printf("WriteFILEError");}for(s=1;s<=5;s++){fscanf(IN,"%d",&t);o=fun(t);fprintf(OUT,"%fn",o);}fclose(IN);fclose(OUT);}答案:----------------------doublea=1;inti;for(i=1;ivoidwwjt();longfun(longs,longt){/**********Program**********//**********End**********/}returnt;}main(){longs,t=0,m;printf("nPleaseenters:");scanf("%ld",&s);m=fun(s,t);printf("Theresultis:%ldn",m);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;longi,t=0,m;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<5;n++){fscanf(IN,"%ld",&i);m=fun(i,t);fprintf(OUT,"%ldn",m);}fclose(IN);fclose(OUT);}答案:----------------------longsl=10;t=s%10;while(s>0){s=s/100;t=s%10*sl+t;sl=sl*10;----------------------第80题题号:401------------------------------------------功能:若x、y为奇数,求x到y之间的奇数和;若x、y为偶数,则求x到y之间的偶数和。------------------------------------------#includevoidwwjt();intfun(intx,inty){/**********Program**********//**********End**********/}main(){ints;s=fun(1,1999)-fun(2,1998);printf("s=%dn",s);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;inti[2];into;IN=fopen("in.dat","r");if(IN==NULL)[printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<2;n++){fscanf(IN,"%d",&i[n]);}o=fun(i[0],i[1]);fprintf(OUT,"%dn",o);fclose(IN);fclose(OUT);}答案:----------------------inti,s=0;for(i=x;i<=y;i+=2)s=s+i;returns;----------------------第81题题号:345------------------------------------------功能:将两个两位数的正整数a、b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的千位和十位上,b数的十位和个位数依次放在c数的个位和百位上。例如:当a=45,b=12。调用该函数后,c=4251。------------------------------------------#includevoidwwjt();voidfun(inta,intb,long*c){/**********Program**********//**********End**********/}main(){inta,b;longc;printf("inputa,b:");scanf("%d%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ldn",c);wwjt();}voidwwjt(){FILE*rf,*wf;inti,a,b;longc;rf=fopen("in.dat","r");wf=fopen("out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%d,%d",&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ldn",a,b,c);}fclose(rf);fclose(wf);}答案:----------------------*c=a/10*1000+a%10*10+b/10+b%10*100;----------------------第82题题号:380------------------------------------------功能:用辗转相除法求两个整数的最大公约数。------------------------------------------#includevoidwwjt();intgcd(intn,intm){/**********Program**********//**********End**********/}main(){intn,m,result;scanf("%d%d",&n,&m);result=gcd(n,m);printf("thegcdis%dn",result);第35页共35页n程序设计题wwjt();}voidwwjt(){FILE*IN,*OUT;intm,n;inti[2];into;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<6;n++){for(m=0;m<2;m++){fscanf(IN,"%d",&i[m]);}o=gcd(i[0],i[1]);fprintf(OUT,"%dn",o);}fclose(IN);fclose(OUT);}答案:----------------------intr,t;if(nvoidwwjt();intfun(intm){/**********Program**********//**********End**********/}main(){inty;y=fun(20);printf("y=%dn",y);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN,iOUT,i;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%dn",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------inti,k,s=0;for(i=2;i<=m;i++){for(k=2;kvoidwwjt();longfun(intn,intk){/**********Program**********//**********End**********/}main(){longintsum;printf("Sumof%dpowersofintegersfrom1to%d=",K,N);sum=fun(N,K);printf("%ldn",sum);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;inti[2];longo;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<2;n++){fscanf(IN,"%d",&i[n]);}o=fun(i[0],i[1]);fprintf(OUT,"%ldn",o);fclose(IN);fclose(OUT);}答案:----------------------longpower,sum=0;inti,j;for(i=1;i<=n;i++){power=i;for(j=1;jvoidwwjt();voidchange(charstr[]){/**********Program**********//**********End**********/}main(){voidchange();charstr[40];gets(str);change(str);puts(str);wwjt();}voidwwjt(){FILE*IN,*OUT;chari[200];IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}fscanf(IN,"%s",i);change(i);fprintf(OUT,"%sn",i);fclose(IN);fclose(OUT);}答案:----------------------inti;for(i=0;str[i]!='';i++)第35页共35页n程序设计题if(str[i]>='a'&&str[i]<='z')str[i]=str[i]-32;----------------------第86题题号:316------------------------------------------功能:统计出若干个学生的平均成绩,最高分以及得最高分的人数。例如:输入10名学生的成绩分别为92,87,68,56,92,84,67,75,92,66,则输出平均成绩为77.9,最高分为92,得最高分的人数为3人。------------------------------------------#includevoidwwjt();floatMax=0;intJ=0;floatfun(floatarray[],intn){/**********Program**********//**********End**********/}main(){floata[10],ave;inti=0;for(i=0;i<10;i++)scanf("%f",&a[i]);ave=fun(a,10);printf("ave=%fn",ave);printf("max=%fn",Max);printf("Total:%dn",J);wwjt();}voidwwjt(){FILE*IN,*OUT;floatiIN[10],iOUT;intiCOUNT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(iCOUNT=0;iCOUNT<10;iCOUNT++)fscanf(IN,"%f",&iIN[iCOUNT]);iOUT=fun(iIN,10);fprintf(OUT,"%f%fn",iOUT,Max);fclose(IN);fclose(OUT);}答案:----------------------inti;floatsum=0,ave;Max=array[0];for(i=0;ivoidwwjt();intaverage_num(inta[],intn){/**********Program**********//**********End**********/}main(){intn,a[100],i,num;scanf("%d",&n);for(i=0;ia[i])k++;return(k);----------------------第88题题号:310------------------------------------------功能:计算并输出给定整数n的所有因子之和(不包括1与自身)。注意:n的值不大于1000。例如:n的值为855时,应输出704。------------------------------------------#includevoidwwjt();intfun(intn){/**********Program**********//**********End**********/}main(){printf("s=%dn",fun(855));wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN,iOUT,i;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%dn",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------ints=0,i;for(i=2;i------------------------------------------题目:从键盘输入一个大写字母,要求改用小写字母输出。------------------------------------------#includevoidwwjt();charfun(charc){/**********Program**********//**********End**********/}voidmain(){charc1,c2;第35页共35页n程序设计题printf("Pleaseinputachar:");c1=getchar();printf("%c,%dn",c1,c1);c2=fun(c1);printf("%c,%dn",c2,c2);wwjt();}voidwwjt(){FILE*IN,*OUT;inti;chariIN,iOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%c",&iIN);iOUT=fun(iIN);fprintf(OUT,"%cn",iOUT);}fclose(IN);fclose(OUT);}答案:c=c+32;returnc;第90题题号:400------------------------------------------功能:编写main程序调用函数fact求解从m个元素选n个元素的组合数的个数。计算公式是:组合数=m!/(n!.(m-n)!)。要求:m不能小于n,否则应有容错处理。说明:函数fact(x)的功能是求x!。------------------------------------------#includevoidwwjt();longfact(intx){longy;inti;y=1;for(i=1;i<=x;i++)y=y*i;returny;}main(){intm,n;longzhsgs;printf("请输入m和n:n");scanf("%d%d",&m,&n);/**********Program**********//**********End**********/printf("从%d个元素选%d个元素的组合数的个数是:%dn",m,n,zhsgs);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;inti;longo;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<5;n++){fscanf(IN,"%d",&i);o=fact(i);fprintf(OUT,"%ldn",o);}fclose(IN);fclose(OUT);}答案:----------------------while(mvoidwwjt();doublefun(intm){/**********Program**********//**********End**********/}main(){printf("ji=%fn",fun(100));wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN,i;doubledOUT;IN=fopen("23.IN","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("23.out","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<10;i++){fscanf(IN,"%d",&iIN);dOUT=fun(iIN);fprintf(OUT,"%fn",dOUT);}fclose(IN);fclose(OUT);}答案:----------------------doubley=1;inti;for(i=1;i<=m;i++)if(i%2==0)y*=i;returny;----------------------第92题题号:352------------------------------------------功能:根据整型形参m,计算如下公式的值:y=1/2+1/4+1/6+...+1/2m。例如:若m=9,则应输出:1.414484------------------------------------------#includevoidwwjt();doublefun(intm){/**********Program**********//**********End**********/}main(){intn;printf("Entern:");scanf("%d",&n);printf("nTheresultis%1fn",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;i<5;i++){fscanf(IN,"%d",&t);o=fun(t);fprintf(OUT,"%fn",o);}fclose(IN);fclose(OUT);}第35页共35页n程序设计题答案:----------------------doubley=0;inti;for(i=1;i<=m;i++){y+=1.0/(2*i);}return(y);----------------------第93题题号:383------------------------------------------功能:用函数实现字符串的复制,不允许用strcpy()函数。------------------------------------------#includevoidwwjt();voidcopy(charstr1[],charstr2[]){/**********Program**********//**********End**********/}main(){voidcopy();charc1[40],c2[40];gets(c1);copy(c1,c2);puts(c2);wwjt();}voidwwjt(){FILE*IN,*OUT;chari[100];charo[100];IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}fscanf(IN,"%s",i);copy(i,o);fprintf(OUT,"%sn",o);fclose(IN);fclose(OUT);}答案:----------------------inti;for(i=0;str1[i]!='';i++)str2[i]=str1[i];str2[i]='';----------------------第94题题号:313------------------------------------------功能:从键盘为一维整型数组输入10个整数,调用fun函数找出其中最小的数,并在main函数中输出。------------------------------------------#includevoidwwjt();intfun(intx[],intn){/**********Program**********//**********End**********/}main(){inta[10],i,min;for(i=0;i<10;i++)scanf("%d",&a[i]);for(i=0;i<10;i++)printf("%3d",a[i]);printf("n");min=fun(a,10);printf("%dn",min);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN[10],i;intiOUT,iCOUNT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..ItMayBeChanged");}for(i=0;i<5;i++){for(iCOUNT=0;iCOUNT<10;iCOUNT++)fscanf(IN,"%d",&iIN[iCOUNT]);iOUT=fun(iIN,10);fprintf(OUT,"%dn",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------intmin,i;min=x[0];for(i=1;ivoidwwjt();longfun(intm,intn){/**********Program**********//**********End**********/}main(){intm,n;longs;longfun(int,int);printf("输入m和n的值:");scanf("%d,%d",&m,&n);s=fun(m,n);printf("s=%ldn",s);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;inti[2];longo;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<2;n++){fscanf(IN,"%d",&i[n]);}o=fun(i[0],i[1]);fprintf(OUT,"%ldn",o);fclose(IN);fclose(OUT);}答案:----------------------longintx=1;inti;for(i=1;i<=n;i++)x=x*m;returnx;----------------------第96题题号:23------------------------------------------功能:从键盘输入一个大于3的整数,调用函数fun判断其是否素数,然后在main函数中输出相应的结论信息。例如:7是素数,8不是素数。请编写fun函数。素数是仅能被1和自身整除的数-------------------------------------------#includevoidwwjt();intfun(intn){/**********Program**********//**********End**********/}main(){intm,flag;printf("inputaninteger:");scanf("%d",&m);flag=fun(m);if(flag)printf("%disaprime.n",m);第35页共35页n程序设计题elseprintf("%disnotaprime.n",m);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN,iOUT,i;IN=fopen("5.IN","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("5.out","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<10;i++){fscanf(IN,"%d",&iIN);iOUT=fun(iIN);fprintf(OUT,"%dn",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------inti;intj;j=1;for(i=2;i#include"math.h"voidwwjt();doublefun(intm){/**********Program**********//**********End**********/}main(){intn;printf("Entern:");scanf("%d",&n);printf("nTheresultis%1fn",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;i<5;i++){fscanf(IN,"%d",&t);o=fun(t);fprintf(OUT,"%fn",o);}fclose(IN);fclose(OUT);}答案:----------------------doubley=0;y=sin(m)*10;return(y);----------------------第98题题号:335------------------------------------------功能:求一个n位自然数的各位数字的积。(n是小于10的自然数)------------------------------------------#include#include"conio.h"voidwwjt();longfun(longn){/**********Program**********//**********End**********/}main(){longm;printf("Enterm:");scanf("%ld",&m);printf("nTheresultis%ldn",fun(m));wwjt();}voidwwjt(){FILE*IN,*OUT;intc;longt;longo;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,"%ld",&t);o=fun(t);fprintf(OUT,"%ldn",o);}fclose(IN);fclose(OUT);}答案:----------------------longd,s=1;while(n>0){d=n%10;s*=d;n/=10;}returns;----------------------第99题题号:509------------------------------------------功能:编写函数fun其功能是:根据整型形参m,计算如下公式的值:y=1+1/3+1/5+1/7+…+1/(2m+1)例如:若m=9,则应输出:2.133256------------------------------------------#includevoidwwjt();doublefun(intm){/**********Program**********//**********End**********/}main(){intn;printf("Entern:");scanf("%d",&n);printf("nTheresultis%1fn",fun(n));wwjt();}voidwwjt(){FILE*IN,*OUT;ints,i;intt;floato;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(i=0;i<5;i++){fscanf(IN,"%d",&t);o=fun(t);fprintf(OUT,"%fn",o);}fclose(IN);fclose(OUT);}答案:----------------------doubley=1;inti;for(i=1;i<=m;i++)第35页共35页n程序设计题{y+=1.0/(2*i+1);}return(y);----------------------第100题题号:22------------------------------------------功能:从键盘为一维整型数组输入10个整数,调用fun函数找出其中最小的数,并在main函数中输出。请编写fun函数。------------------------------------------#include"stdio.h"voidwwjt();intfun(intx[],intn){/**********Program**********//**********End**********/}main(){inta[10],i,min;for(i=0;i<10;i++)scanf("%d",&a[i]);for(i=0;i<10;i++)printf("%3d",a[i]);printf("n");min=fun(a,10);printf("%dn",min);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN[10],i;intiOUT,iCOUNT;IN=fopen("4.IN","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("4.out","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<10;i++){for(iCOUNT=0;iCOUNT<10;iCOUNT++)fscanf(IN,"%d",&iIN[iCOUNT]);iOUT=fun(iIN,10);fprintf(OUT,"%dn",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------intmin,i;min=x[0];for(i=1;i#includevoidwwjt();voidsort(inta[],intn){/**********Program**********//**********End**********/}main(){inta[13],i;for(i=0;i<13;i++)a[i]=random(20)-5;for(i=0;i<13;i++)printf("%3d",a[i]);printf("n-------------------n");sort(a,13);for(i=0;i<13;i++)printf("%3d",a[i]);wwjt();}voidwwjt(){FILE*IN,*OUT;intn;inti[10];IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<10;n++){fscanf(IN,"%d",&i[n]);}sort(i,10);for(n=0;n<10;n++)fprintf(OUT,"%dn",i[n]);fclose(IN);fclose(OUT);}答案:----------------------inti,j,k,t;for(i=0;ia[j])k=j;if(k!=i){t=a[i];a[i]=a[k];a[k]=t;}}第102题题号:321------------------------------------------功能:编写函数fun其功能是:根据整型形参m,计算如下公式的值:y=1/2!+1/4!+…+1/m!(m是偶数)------------------------------------------#includevoidwwjt();doublefun(intm){/**********Program**********//**********End**********/}main(){intn;printf("Entern:");scanf("%d",&n);printf("nTheresultis%1fn",fun(n));wwjt();}voidwwjt(){FILE*IN,*OUT;intt;doubleo;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,"%fn",o);}fclose(IN);fclose(OUT);}答案:doubley=0.0;inti,j;doubles=1;for(i=2;i<=m;i+=2){for(j=i-1;j<=i;j++)s=s*j;y=y+1.0/s;}returny;第103题题号:328------------------------------------------功能:求k!(k〈13),所求阶乘的值作为函数值返回。(要求使用递归)------------------------------------------#include#include"conio.h"voidwwjt();longfun(intk){/**********Program**********//**********End**********/}main(){intm;第35页共35页n程序设计题printf("Enterm:");scanf("%d",&m);printf("nTheresultis%ldn",fun(m));wwjt();}voidwwjt(){FILE*IN,*OUT;ints;intt;longo;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(s=1;s<=5;s++){fscanf(IN,"%d",&t);o=fun(t);fprintf(OUT,"%ldn",o);}fclose(IN);fclose(OUT);}答案:----------------------if(k>0)return(k*fun(k-1));elseif(k==0)return1L;第104题题号:354------------------------------------------功能:求小于lim的所有素数并放在aa数组中,该函数返回所求出素数的个数。------------------------------------------#include#include#defineMAX100voidwwjt();intfun(intlim,intaa[MAX]){/**********Program**********//**********End**********/}main(){intlimit,i,sum;intaa[MAX];printf("Pleaseinputainteger:");scanf("%d",&limit);sum=fun(limit,aa);for(i=0;ivoidwwjt();main(){inti,j,s,a[3][3];;for(i=0;i<3;i++){for(j=0;j<3;j++)scanf("%d",&a[i][j]);}s=fun(a);printf("Sum=%dn",s);wwjt();}intfun(inta[3][3]){/**********Program**********//**********End**********/}voidwwjt(){FILE*IN,*OUT;intm;intn;inti[3][3];into;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(m=0;m<3;m++){for(n=0;n<3;n++)fscanf(IN,"%d",&i[m][n]);}o=fun(i);{fprintf(OUT,"%dn",o);getch();}fclose(IN);fclose(OUT);}答案:----------------------intsum;inti;sum=0;for(i=0;i<3;i++)sum=sum+a[i][i]*a[i][i];returnsum;----------------------第106题题号:390------------------------------------------功能:编写函数求1~100中奇数的平方和。结果为166650。------------------------------------------#includevoidwwjt();floatsum(intn){/**********Program**********//**********End**********/}main(){printf("sum=%fn",sum(100));wwjt();}voidwwjt(){FILE*IN,*OUT;inti;floato;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}fscanf(IN,"%d",&i);o=sum(i);fprintf(OUT,"%fn",o);fclose(IN);fclose(OUT);}答案:----------------------floats=0;inti;for(i=1;i<=n;i=i+2)s=s+i*i;return(s);----------------------第35页共35页n程序设计题第107题题号:396------------------------------------------功能:编写函数fun用比较法对主程序中用户输入的具有10个数据的数组a按由大到小排序,并在主程序中输出排序结果。------------------------------------------#includevoidwwjt();intfun(intarray[],intn){/**********Program**********//**********End**********/}main(){inta[10],i;printf("请输入数组a中的十个数:n");for(i=0;i<10;i++)scanf("%d",&a[i]);fun(a,10);printf("由大到小的排序结果是:n");for(i=0;i<10;i++)printf("%4d",a[i]);printf("n");wwjt();}voidwwjt(){FILE*IN,*OUT;intn;inti[10];IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(n=0;n<10;n++){fscanf(IN,"%d",&i[n]);}fun(i,10);for(n=0;n<10;n++){fprintf(OUT,"%dn",i[n]);}fclose(IN);fclose(OUT);}答案:----------------------intk,j,t;for(k=0;kvoidwwjt();voidrow_sum(inta[5][4],intb[5]){/**********Program**********//**********End**********/}main(){voidrow_sum();inta[5][4],b[5],i,j;for(i=0;i<5;i++)for(j=0;j<4;j++)a[i][j]=random(120-30+1)+30;for(i=0;i<5;i++){for(j=0;j<4;j++)printf("%5d",a[i][j]);printf("n");}row_sum(a,b);for(i=0;i<5;i++)printf("%6d",b[i]);printf("n");wwjt();}voidwwjt(){FILE*IN,*OUT;intm,n;inti[5][4];into[5];IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(m=0;m<5;m++)for(n=0;n<4;n++)fscanf(IN,"%d",&i[m][n]);row_sum(i,o);for(n=0;n<5;n++)fprintf(OUT,"%dn",o[n]);fclose(IN);fclose(OUT);}答案:----------------------inti,j;for(i=0;i<5;i++){b[i]=0;for(j=0;j<4;j++)b[i]=b[i]+a[i][j];}----------------------第109题题号:368------------------------------------------功能:求一分数序列2/1,3/2,5/3,8/5,13/8,21/13…的前n项之和。说明:每一分数的分母是前两项的分母之和,每一分数的分子是前两项的分子之和例如:求前20项之和的值为32.660259。------------------------------------------#includevoidwwjt();floatfun(intn){/**********Program**********//**********End**********/}main(){floaty;y=fun(20);printf("y=%fn",y);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN,i;floatfOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<5;i++){fscanf(IN,"%d",&iIN);fOUT=fun(iIN);fprintf(OUT,"%fn",fOUT);}fclose(IN);fclose(OUT);}答案:----------------------inti;floatf1=1,f2=1,f3,s=0;for(i=1;i<=n;i++){f3=f1+f2;f1=f2;f2=f3;s=s+f2/f1;}returns;----------------------第110题题号:452------------------------------------------功能:有一个一维数组score,内放10个学生的个函数来求平均成绩。例如:如果10个学生的成绩分别为92,87,68,56,92,84,70,65,90,60第35页共35页n程序设计题则平均成绩为:76.400000------------------------------------------#includevoidwwjt();floataverage(floatarray[10]){/**********Program**********//**********End**********/}main(){floatscore[]={92,87,68,56,92,84,70,65,90,60};printf("averagescoreis%fn",average(score));wwjt();}voidwwjt(){FILE*IN,*OUT;inti;floatfIN[10];floatfOUT;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}for(i=0;i<10;i++){fscanf(IN,"%f",&fIN[i]);}fOUT=average(fIN);fprintf(OUT,"%fn",fOUT);fclose(IN);fclose(OUT);}答案:----------------------inti;floataver,sum=array[0];for(i=1;i<10;i++)sum=sum+array[i];aver=sum/10;returnaver;----------------------第111题题号:330------------------------------------------功能:计算出k以内最大的10个能被13或17整除的自然数之和。(k〈3000)。------------------------------------------#include#include"conio.h"voidwwjt();intfun(intk){/**********Program**********//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("nTheresultis%dn",fun(m));wwjt();}voidwwjt(){FILE*IN,*OUT;ints;intt;into;IN=fopen("in.dat","r");if(IN==NULL){printf("ReadFILEError");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("WriteFILEError");}for(s=1;s<=5;s++){fscanf(IN,"%d",&t);o=fun(t);fprintf(OUT,"%dn",o);}fclose(IN);fclose(OUT);}答案:----------------------inta=0,b=0;while((k>=2)&&(b<10)){if((k%13==0)||(k%17==0)){a=a+k;b++;}k--;}returna;----------------------第112题题号:363------------------------------------------功能:求一个给定字符串中的字母的个数。------------------------------------------#includevoidwwjt();intfun(chars[]){/**********Program**********//**********End**********/}main(){charstr[]="Bestwishesforyou!";intk;k=fun(str);printf("k=%dn",k);wwjt();}voidwwjt(){FILE*IN,*OUT;charsin[80];intiOUT,i;IN=fopen("in.dat","r");if(IN==NULL){printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..ItMayBeChanged");}for(i=0;i<10;i++){fscanf(IN,"%s",sin);iOUT=fun(sin);}fprintf(OUT,"%dn",iOUT);fclose(IN);fclose(OUT);}答案:----------------------inti,k=0;for(i=0;s[i]!='';i++)if(s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z')k++;returnk;----------------------第113题题号:315------------------------------------------功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。------------------------------------------#include#include#include#defineN81voidwwjt();voidfun(char*str,intn){/**********Program**********//**********End**********/}main(){chars[N];intl;printf("inputastring:");gets(s);l=strlen(s);fun(s,l);printf("Thenewstringis:");puts(s);wwjt();}voidwwjt(){FILE*IN,*OUT;charsin[20],*sOUT;intiLENGTH;IN=fopen("in.dat","r");if(IN==NULL)第35页共35页n程序设计题{printf("PleaseVerifyTheCurrerntDir..itMayBeChanged");}OUT=fopen("out.dat","w");if(OUT==NULL){printf("PleaseVerifyTheCurrentDir..itMayBeChanged");}fscanf(IN,"%s",sin);iLENGTH=strlen(sin);sOUT=sin;fun(sin,iLENGTH);fprintf(OUT,"%sn",sOUT);fclose(IN);fclose(OUT);}答案:----------------------inti,j;charc;for(i=0,j=n-1;i
查看更多

相关文章