萬維考試系統(tǒng)-C語言試題庫-程序設(shè)計題導(dǎo)出-113道_第1頁
萬維考試系統(tǒng)-C語言試題庫-程序設(shè)計題導(dǎo)出-113道_第2頁
萬維考試系統(tǒng)-C語言試題庫-程序設(shè)計題導(dǎo)出-113道_第3頁
萬維考試系統(tǒng)-C語言試題庫-程序設(shè)計題導(dǎo)出-113道_第4頁
萬維考試系統(tǒng)-C語言試題庫-程序設(shè)計題導(dǎo)出-113道_第5頁
已閱讀5頁,還剩142頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

...wd......wd......wd...一、程序設(shè)計共113題〔共計1130分〕第1題〔10.0分〕題號:390/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:編寫函數(shù)求1~100中奇數(shù)的平方和。結(jié)果為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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:在鍵盤上輸入一個3行3列矩陣的各個元素的值〔值為整數(shù)〕,然后輸出主對角線元素的積,并在fun()函數(shù)中輸出。------------------------------------------------*/#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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:能計算從1開場到n的自然數(shù)中偶數(shù)的平方的和,n由鍵盤輸入,并在main()函數(shù)中輸出?!瞡是偶數(shù)〕------------------------------------------------*/#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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:將兩個兩位數(shù)的正整數(shù)a、b合并形成一個整數(shù)放在c中。合并的方式是:將a數(shù)的十位和個位數(shù)依次放在c數(shù)的千位和十位上,b數(shù)的十位和個位數(shù)依次放在c數(shù)的個位和百位上。例如:當(dāng)a=45,b=12。調(diào)用該函數(shù)后,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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:求一組數(shù)中大于平均值的數(shù)的個數(shù)。例如:給定的一組數(shù)為1,3,6,9,4,23,35,67,12,88時,函數(shù)值為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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:對長度為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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:求出二維數(shù)組周邊元素之和,作為函數(shù)值返回。二維數(shù)組的值在主函數(shù)中賦予。-------------------------------------------------*/#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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:判斷整數(shù)x是否是同構(gòu)數(shù)。假設(shè)是同構(gòu)數(shù),函數(shù)返回1;否則返回0。x的值由主函數(shù)從鍵盤讀入,要求不大于100。說明:所謂“同構(gòu)數(shù)〞是指這樣的數(shù),這個數(shù)出現(xiàn)在它的平方數(shù)的右邊。例如:輸入整數(shù)5,5的平方數(shù)是25,5是25中右側(cè)的數(shù),所以5是同構(gòu)數(shù)。------------------------------------------------*/#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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:用函數(shù)實現(xiàn)字符串的復(fù)制,不允許用strcpy()函數(shù)。------------------------------------------------*/#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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:計算并輸出給定整數(shù)n的所有因子之和〔不包括1與自身〕。注意:n的值不大于1000。例如:n的值為855時,應(yīng)輸出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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:求小于lim的所有素數(shù)并放在aa數(shù)組中,該函數(shù)返回所求出素數(shù)的個數(shù)。 ------------------------------------------------*/#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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:刪除所有值為y的元素。數(shù)組元素中的值和y的值由主函數(shù)通過鍵盤輸入。------------------------------------------------*/#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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:求出N×M整型數(shù)組的最大元素及其所在的行坐標(biāo)及列坐標(biāo)〔如果最大元素不唯一,選擇位置在最前面的一個〕。例如:輸入的數(shù)組為:12341561218910112求出的最大數(shù)為18,行坐標(biāo)為2,列坐標(biāo)為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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:求一批數(shù)中最大值和最小值的積。------------------------------------------------*/#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>/*-------------------------------------------------------【程序設(shè)計】---------------------------------------------------------題目:從鍵盤輸入一個大寫字母,要求改用小寫字母輸出。-------------------------------------------------------*/#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>/*-------------------------------------------------------【程序設(shè)計】---------------------------------------------------------題目:用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/*-------------------------------------------------------【程序設(shè)計】---------------------------------------------------------題目:輸入華氏溫度求攝氏溫度。轉(zhuǎn)換公式為c=5/9〔f-32〕,輸出結(jié)果取兩位小數(shù)。-------------------------------------------------------*/#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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:對任意輸入的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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:給定n個數(shù)據(jù),求最小值出現(xiàn)的位置〔如果最小值出現(xiàn)屢次,求出第一次出現(xià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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:找出一批正整數(shù)中的最大的偶數(shù)。------------------------------------------------*/#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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:產(chǎn)生20個[30,120]上的隨機(jī)整數(shù)放入二維數(shù)組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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:求給定正整數(shù)n以內(nèi)的素數(shù)之積?!瞡<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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:求一個給定字符串中的字母的個數(shù)。------------------------------------------------*/#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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:編寫程序,求矩陣〔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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:編寫main程序調(diào)用函數(shù)fact求解從m個元素選n個元素的組合數(shù)的個數(shù)。計算公式是:組合數(shù)=m!/(n!.(m-n)!)。要求:m不能小于n,否則應(yīng)有容錯處理。說明:函數(shù)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個元素的組合數(shù)的個數(shù)是:%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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:對任意輸入的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/*------------------------------------------------【程序設(shè)計】--------------------------------------------------功能:編寫函數(shù)fun其功能是:根據(jù)整型形參m,計算如下公式的值:y=1+1/3+1/5+1/7+…+1/(2m+1)例如:假設(shè)m=9,則應(yīng)輸出: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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論