版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
...wd......wd......wd...一、程序设计共113题〔共计1130分〕第1题〔10.0分〕题号:390/*------------------------------------------------【程序设计】--------------------------------------------------功能:编写函数求1~100中奇数的平方和。结果为166650.000000。------------------------------------------------*/#include<stdio.h>voidwwjt();floatsum(intn){/**********Program**********//**********End**********/}答案:----------------------floats=0;inti;for(i=1;i<=n;i=i+2)s=s+i*i;return(s);----------------------第2题〔10.0分〕题号:320/*------------------------------------------------【程序设计】--------------------------------------------------功能:在键盘上输入一个3行3列矩阵的各个元素的值〔值为整数〕,然后输出主对角线元素的积,并在fun()函数中输出。------------------------------------------------*/#include<stdio.h>voidwwjt();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=%d\n",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,"%d\n",o);getch();}fclose(IN);fclose(OUT);}答案:----------------------intsum;inti,j;sum=1;for(i=0;i<3;i++)sum=sum*a[i][i];returnsum;----------------------第3题〔10.0分〕题号:324/*------------------------------------------------【程序设计】--------------------------------------------------功能:能计算从1开场到n的自然数中偶数的平方的和,n由键盘输入,并在main()函数中输出。〔n是偶数〕------------------------------------------------*/#include<stdio.h>voidwwjt();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);----------------------第4题〔10.0分〕题号:345/*------------------------------------------------【程序设计】--------------------------------------------------功能:将两个两位数的正整数a、b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的千位和十位上,b数的十位和个位数依次放在c数的个位和百位上。例如:当a=45,b=12。调用该函数后,c=4251。------------------------------------------------*/#include<stdio.h>voidwwjt();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:%ld\n",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=%ld\n",a,b,c);}fclose(rf);fclose(wf);}答案:----------------------*c=a/10*1000+a%10*10+b/10+b%10*100;----------------------第5题〔10.0分〕题号:366/*------------------------------------------------【程序设计】--------------------------------------------------功能:求一组数中大于平均值的数的个数。例如:给定的一组数为1,3,6,9,4,23,35,67,12,88时,函数值为3。------------------------------------------------*/#include<stdio.h>voidwwjt();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=%d\n",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,"%d\n",iOUT);fclose(IN);fclose(OUT);}答案:----------------------inti,k=0;floats=0,ave;for(i=0;i<n;i++)s+=a[i];ave=s/n;printf("%f",ave);for(i=0;i<n;i++)if(a[i]>ave)k++;returnk;----------------------第6题〔10.0分〕题号:355/*------------------------------------------------【程序设计】--------------------------------------------------功能:对长度为8个字符的字符串,将8个字符按降序排列。例如:原来的字符串为CEAedcab,排序后输出为edcbaECA。------------------------------------------------*/Firefox答案:----------------------inti,j;chart;for(i=0;i<num;i++)for(j=i+1;j<num;j++)if(s[i]<s[j]){t=s[i];s[i]=s[j];s[j]=t;}----------------------第7题〔10.0分〕题号:44/*------------------------------------------------【程序设计】--------------------------------------------------功能:求出二维数组周边元素之和,作为函数值返回。二维数组的值在主函数中赋予。-------------------------------------------------*/#defineM4#defineN5#include<stdio.h>voidwwjt();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=%d\n",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;i<M;i++)for(j=0;j<N;j++)fscanf(IN,"%d",&iIN[i][j]);iOUT=fun(iIN);fprintf(OUT,"%d\n",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------ints=0;inti,j;for(i=0;i<M;i++)s=s+a[i][0]+a[i][N-1];for(j=1;j<N-1;j++)s=s+a[0][j]+a[M-1][j];returns;----------------------第8题〔10.0分〕题号:339/*------------------------------------------------【程序设计】--------------------------------------------------功能:判断整数x是否是同构数。假设是同构数,函数返回1;否则返回0。x的值由主函数从键盘读入,要求不大于100。说明:所谓“同构数〞是指这样的数,这个数出现在它的平方数的右边。例如:输入整数5,5的平方数是25,5是25中右侧的数,所以5是同构数。------------------------------------------------*/#include<stdio.h>voidwwjt();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("%dYES\n",x);elseprintf("%dNO\n",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,"%d\n",o);}fclose(IN);fclose(OUT);}答案:----------------------intk;k=x*x;if((k%10==x)||(k%100==x))return1;elsereturn0;----------------------第9题〔10.0分〕题号:383/*------------------------------------------------【程序设计】--------------------------------------------------功能:用函数实现字符串的复制,不允许用strcpy()函数。------------------------------------------------*/#include<stdio.h>voidwwjt();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,"%s\n",o);fclose(IN);fclose(OUT);}答案:----------------------inti;for(i=0;str1[i]!='\0';i++)str2[i]=str1[i];str2[i]='\0';----------------------第10题〔10.0分〕题号:310/*------------------------------------------------【程序设计】--------------------------------------------------功能:计算并输出给定整数n的所有因子之和〔不包括1与自身〕。注意:n的值不大于1000。例如:n的值为855时,应输出704。------------------------------------------------*/#include<stdio.h>voidwwjt();intfun(intn){/**********Program**********//**********End**********/}main(){printf("s=%d\n",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,"%d\n",iOUT);}fclose(IN);fclose(OUT);}答案:----------------------ints=0,i;for(i=2;i<n;i++)if(n%i==0)s=s+i;returns;----------------------第11题〔10.0分〕题号:354/*------------------------------------------------【程序设计】--------------------------------------------------功能:求小于lim的所有素数并放在aa数组中,该函数返回所求出素数的个数。 ------------------------------------------------*/#include<stdio.h>#include<conio.h>#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;i<sum;i++){if(i%10==0&&i!=0)printf("\n");printf("%5d",aa[i]);}wwjt();}voidwwjt(){inti,j,array[100],sum,lim;FILE*rf,*wf;rf=fopen("in.dat","r");wf=fopen("out.dat","w");for(j=0;j<=5;j++){fscanf(rf,"%d",&lim);sum=fun(lim,array);for(i=0;i<sum;i++)fprintf(wf,"%7d",array[i]);fprintf(wf,"\n");}fclose(rf);fclose(wf);}答案:----------------------intn=0;inti,j;for(i=2;i<=lim;i++){for(j=2;j<i;j++)if(i%j==0)break;if(j==i)aa[n++]=i;}returnn;----------------------第12题〔10.0分〕题号:341/*------------------------------------------------【程序设计】--------------------------------------------------功能:删除所有值为y的元素。数组元素中的值和y的值由主函数通过键盘输入。------------------------------------------------*/#include<stdio.h>#include<conio.h>#include<stdio.h>#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;k<n;k++)scanf("%d",&aa[k]);printf("Theoriginaldatais:\n");for(k=0;k<n;k++)printf("%5d",aa[k]);printf("\nEnteranumbertodeletede:");scanf("%d",&y);fun(aa,&n,y);printf("Thedataafterdeleted%d:\n",y);for(k=0;k<n;k++)printf("%4d",aa[k]);printf("\n");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]);}fun(i,&n,3);for(o=0;o<n;o++){fprintf(OUT,"%d\n",i[o]);}fclose(IN);fclose(OUT);}答案:----------------------inti,j;for(i=0;i<*n;){if(bb[i]==y){for(j=i;j<*n;j++)bb[j]=bb[j+1];*n=*n-1;}elsei++;}----------------------第13题〔10.0分〕题号:317/*------------------------------------------------【程序设计】--------------------------------------------------功能:求出N×M整型数组的最大元素及其所在的行坐标及列坐标〔如果最大元素不唯一,选择位置在最前面的一个〕。例如:输入的数组为:12341561218910112求出的最大数为18,行坐标为2,列坐标为1。------------------------------------------------*/#defineN4#defineM3#include<stdio.h>voidwwjt();intRow,Col;intfun(intarray[N][M]){/**********Program**********//**********End**********/}main(){inta[N][M],i,j,max;printf("inputaarray:");for(i=0;i<N;i++)for(j=0;j<M;j++)scanf("%d",&a[i][j]);for(i=0;i<N;i++){for(j=0;j<M;j++)printf("%d",a[i][j]);printf("\n");}max=fun(a);printf("max=%d,row=%d,col=%d",max,Row,Col);wwjt();}voidwwjt(){FILE*IN,*OUT;intiIN[N][M],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(i=0;i<N;i++)for(j=0;j<M;j++)fscanf(IN,"%d",&iIN[i][j]);iOUT=fun(iIN);fprintf(OUT,"%d%d%d\n",iOUT,Row,Col);fclose(IN);fclose(OUT);}答案:----------------------intmax,i,j;max=array[0][0];Row=0;Col=0;for(i=0;i<N;i++){for(j=0;j<M;j++)if(max<array[i][j]){max=array[i][j];Row=i;Col=j;}}return(max);----------------------第14题〔10.0分〕题号:392/*------------------------------------------------【程序设计】--------------------------------------------------功能:求一批数中最大值和最小值的积。------------------------------------------------*/#defineN30#include"stdlib.h"#include<stdio.h>voidwwjt();intmax_min(inta[],intn){/**********Program**********//**********End**********/}main(){inta[N],i,k;for(i=0;i<N;i++)a[i]=random(51)+10;for(i=0;i<N;i++){printf("%5d",a[i]);if((i+1)%5==0)printf("\n");}k=max_min(a,N);printf("theresultis:%d\n",k);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]);}o=max_min(i,10);fprintf(OUT,"%d\n",o);fclose(IN);fclose(OUT);}答案:----------------------inti,max,min;max=min=a[0];for(i=1;i<n;i++)if(a[i]>max)max=a[i];elseif(a[i]<min)min=a[i];return(max*min);----------------------第15题〔10.0分〕题号:501#include<stdio.h>/*-------------------------------------------------------【程序设计】---------------------------------------------------------题目:从键盘输入一个大写字母,要求改用小写字母输出。-------------------------------------------------------*/#include<stdio.h>voidwwjt();charfun(charc){/**********Program**********//**********End**********/}voidmain(){charc1,c2;printf("Pleaseinputachar:");c1=getchar();printf("%c,%d\n",c1,c1);c2=fun(c1);printf("%c,%d\n",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,"%c\n",iOUT);}fclose(IN);fclose(OUT);}答案:c=c+32;returnc;第16题〔10.0分〕题号:502#include<stdio.h>/*-------------------------------------------------------【程序设计】---------------------------------------------------------题目:用while语句求1~100的累计和。-------------------------------------------------------*/voidwwjt();intfun(intn){/**********Program**********//**********End**********/}voidmain(){intsum=0;sum=fun(100);printf("sum=%d\n",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,"%d\n",iOUT);}fclose(IN);fclose(OUT);}答案:inti=1,sum=0;while(i<=n){ sum=sum+i; i++; }returnsum;第17题〔10.0分〕题号:409/*-------------------------------------------------------【程序设计】---------------------------------------------------------题目:输入华氏温度求摄氏温度。转换公式为c=5/9〔f-32〕,输出结果取两位小数。-------------------------------------------------------*/#include<stdio.h>voidwwjt();doublefun(doublem){/**********Program**********//**********End**********/}voidmain(){doublec,f;printf("请输入一个华氏温度:");scanf("%f",&f);c=fun(f);printf("摄氏温度为:%5.2f\n",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,"%f\n",iOUT);}fclose(IN);fclose(OUT);}答案:floatn;n=(5.0/9.0)*(m-32);returnn;第18题〔10.0分〕题号:29/*------------------------------------------------【程序设计】--------------------------------------------------功能:对任意输入的x,用下式计算并输出y的值。5x<10y=0x=10-5x>10------------------------------------------------*/#include<stdio.h>voidwwjt();intfun(intn){/**********Program**********//**********End**********/}voidmain(){intx,y;printf("enterx:");scanf("%d",&x);y=fun(x);printf("x=%d,y=%d\n",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,"%ld\n",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;第19题〔10.0分〕题号:382/*------------------------------------------------【程序设计】--------------------------------------------------功能:给定n个数据,求最小值出现的位置〔如果最小值出现屡次,求出第一次出现的位置即可〕。------------------------------------------------*/#include<stdio.h>voidwwjt();intstation(ints[],intn){/**********Program**********//**********End**********/}main(){inta[100],n,i,t;scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&a[i]);t=station(a,n);printf("themin_valuepositionis:%d\n",t);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]);}o=station(i,10);fprintf(OUT,"%d\n",o);fclose(IN);fclose(OUT);}答案:----------------------inti,k;k=0;for(i=1;i<n;i++)if(s[i]<s[k])k=i;return(k);----------------------第20题〔10.0分〕题号:367/*------------------------------------------------【程序设计】--------------------------------------------------功能:找出一批正整数中的最大的偶数。------------------------------------------------*/#include<stdio.h>voidwwjt();intfun(inta[],intn){/**********Program**********//**********End**********/}main(){inta[]={1,2,9,24,35,18},k;k=fun(a,6);printf("max=%d\n",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,"%d\n",iOUT);fclose(IN);fclose(OUT);}答案:----------------------inti,amax=-1;for(i=0;i<n;i++)if(a[i]%2==0)if(a[i]>amax)amax=a[i];returnamax;----------------------第21题〔10.0分〕题号:384/*------------------------------------------------【程序设计】--------------------------------------------------功能:产生20个[30,120]上的随机整数放入二维数组a[5][4]中,求每行元素的和。------------------------------------------------*/#include"stdlib.h"#include<stdio.h>voidwwjt();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,"%d\n",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];}----------------------第22题〔10.0分〕题号:334/*------------------------------------------------【程序设计】--------------------------------------------------功能:求给定正整数n以内的素数之积。〔n<28〕------------------------------------------------*/#include<stdio.h>#include"conio.h"voidwwjt();longfun(intn){/**********Program**********//**********End**********/}main(){intm;printf("Enterm:");scanf("%d",&m);printf("\nTheresultis%ld\n",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,"%ld\n",o);}fclose(IN);fclose(OUT);}答案:----------------------longi,k;longs=1;for(i=2;i<=n;i++){for(k=2;k<i;k++)if(i%k==0)break;if(k==i)s=s*i;}returns;----------------------第23题〔10.0分〕题号:363/*------------------------------------------------【程序设计】--------------------------------------------------功能:求一个给定字符串中的字母的个数。------------------------------------------------*/#include<stdio.h>voidwwjt();intfun(chars[]){/**********Program**********//**********End**********/}main(){charstr[]="Bestwishesforyou!";intk;k=fun(str);printf("k=%d\n",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,"%d\n",iOUT);fclose(IN);fclose(OUT);}答案:----------------------inti,k=0;for(i=0;s[i]!='\0';i++)if(s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z')k++;returnk;----------------------第24题〔10.0分〕题号:361/*------------------------------------------------【程序设计】--------------------------------------------------功能:编写程序,求矩阵〔3行3列〕与2的乘积例如:输入下面的矩阵:100200300400500600700800900程序输出:20040060080010001200140016001800------------------------------------------------*/#include<stdio.h>voidwwjt();voidfun(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;for(i=0;i<3;i++)for(j=0;j<3;j++)array[i][j]=array[i][j]*2;----------------------第25题〔10.0分〕题号:400/*------------------------------------------------【程序设计】--------------------------------------------------功能:编写main程序调用函数fact求解从m个元素选n个元素的组合数的个数。计算公式是:组合数=m!/(n!.(m-n)!)。要求:m不能小于n,否则应有容错处理。说明:函数fact(x)的功能是求x!。------------------------------------------------*/#include<stdio.h>voidwwjt();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个元素的组合数的个数是:%d\n",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,"%ld\n",o);}fclose(IN);fclose(OUT);}答案:----------------------while(m<n){printf("m和n输入错!请重新输入:\n");scanf("%d%d",&m,&n);}zhsgs=fact(m)/(fact(n)*fact(m-n));----------------------第26题〔10.0分〕题号:411/*------------------------------------------------【程序设计】--------------------------------------------------功能:对任意输入的x,用下式计算并输出y的值。-1x<0y=0x=01x>0------------------------------------------------*/#include<stdio.h>voidwwjt();intfun(intn){/**********Program**********//**********End**********/}voidmain(){intx,y;printf("enterx:");scanf("%d",&x);y=fun(x);printf("x=%d,y=%d\n",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,"%ld\n",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;第27题〔10.0分〕题号:509/*------------------------------------------------【程序设计】--------------------------------------------------功能:编写函数fun其功能是:根据整型形参m,计算如下公式的值:y=1+1/3+1/5+1/7+…+1/(2m+1)例如:假设m=9,则应输出:2.133256------------------------------------------------*/#include<stdio.h>voidwwjt();doublefun(intm){/**********Program**********//**********End**********/}main(){intn;printf("Entern:");scanf("%d",&n);printf("\nTheresultis%1f\n",fun(n));wwjt();}voidwwjt(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 学习部工作计划范文
- 吉林彩色透水沥青施工方案
- 合肥阳台防水补漏施工方案
- 加油站围墙拆除施工方案
- 2024高一体育教师教学工作计划范文
- 2024部队财务工作计划范文
- 扶贫办工作总结和工作计划
- 2024秋季幼儿园保教工作计划范文
- 《科普健康知识讲座》课件
- 《纳米材料》课件
- iso31000:2009风险管理-原则与实施指南中文版
- 后进生落后表现及原因4篇
- 准确解析BET孔径分析(课堂PPT)
- 如何突破三视图教学几个难点
- 才华横溢摄影作品评分表
- 《预防一氧化碳中毒》PPT课件
- 运行值班管理制度SOP
- 牛吃草问题、工程问题经典例题(含答案版)
- 电线电缆毕业设计毕业设计
- 全科接诊记录(健康档案)书写培训课件
- 毕业设计(论文)工厂供配电系统设计
评论
0/150
提交评论