c語言試題整合_第1頁
c語言試題整合_第2頁
c語言試題整合_第3頁
c語言試題整合_第4頁
c語言試題整合_第5頁
已閱讀5頁,還剩33頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、百科園最終版嘔心瀝血刪減復制加答案八套全集你們一定是上輩子跟著我拯救了銀河系這輩子才會遇到這么好的我!好吧還有605全體.!快跪拜!*1=14*/*-【程序設計】-功能:求5行5列矩陣的主、副對角線上元素之和。注意, 兩條對角線相交的元素只加一次。例如:主函數(shù)中給出的矩陣的兩條對角線的和為45。-*/#include "stdio.h"#define M 5 int fun(int aMM) /*Begin*/ int s=0; int i; for(i=0;i<M;i+) s=s+aii+aiM-1-i; s=s-a(M-1)/2(M-1)/2; return s;

2、 /* End */ void TestFunc() FILE *IN,*OUT; int iINMM,iOUT; int i,j; IN=fopen("in.dat","r"); if(IN=NULL) printf("Please Verify The Currernt Dir.It May Be Changed"); OUT=fopen("out.dat","w"); if(OUT=NULL) printf("Please Verify The Current Dir. It M

3、ay Be Changed"); for(i=0;i<M;i+) for(j=0;j<M;j+) fscanf(IN,"%d",&iINij); iOUT=fun(iIN); fprintf(OUT,"%dn",iOUT); fclose(IN); fclose(OUT);main() int aMM=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; int y; y=fun(a); printf("s=%dn",y); TestFunc();/*-【

4、程序設計】-功能:能計算從1開始到n的自然數(shù)中偶數(shù)的平方的和,n由 鍵盤輸入,并在main()函數(shù)中輸出。(n是偶數(shù))-*/#include <stdio.h>void bky(); int fun(int n) /*Begin*/ int sum,i;sum =0;for(i=2;i<=n;i=i+2)sum=sum+i*i;return(sum); /* End */ main() int m; printf("Enter m: "); scanf("%d", &m); printf("nThe result is

5、 %dn", fun(m); bky(); void bky() FILE *IN,*OUT; int t; int o; int c; IN=fopen("in.dat","r"); if(IN=NULL) printf("Read FILE Error"); OUT=fopen("out.dat","w"); if(OUT=NULL) printf("Write FILE Error"); for(c=1;c<=5;c+) fscanf(IN,"

6、%d",&t); o=fun(t); fprintf(OUT,"%dn",o); fclose(IN); fclose(OUT);/*- 【程序改錯】-功能:在鍵盤上輸入一個3行3列矩陣的各個元素的值(值為整數(shù)), 在fun()函數(shù)中,編寫計算矩陣第一行與第三行元素之積。-*/#include "stdio.h"main() int i,j,s,a33; for(i=0;i<3;i+) for(j=0;j<3;j+) scanf("%d",&aij); s=fun(a); printf("

7、;Sum=%dn",s); int fun(int a33) int i,j,sum; /*ERROR*/ sum=0; sum=1; /*ERROR*/ for(i=0;i<3;i+) for(i=0;i<3;i+=2)for(i=0;i<3;i=i+2)for(i=0;i<3;i+,i+) for(j=0;j<3;j+) /*ERROR*/ sum=*aij; sum=sum*aij;sum*=aij;sum=aij*sum; return sum;/*-【程序填空】-題目:將學生成績80分以上定為'A'等,7079分定為'B

8、'等, 6069分定為'C'等,60分以下定為'D'等。-*/main() float grade; scanf("%f,&grade);/*FILL*/ if(_grade>=60.0_) if(grade>=70.0)/*FILL*/ if(grade>=80.0) _ printf("A");_ else printf("B"); else printf("C"); else printf("D");*2=15*/*-【程序設計】-功

9、能:將從鍵盤上輸入的每個單詞的第一個字母轉(zhuǎn)換為 大寫字母,輸入時各單詞必須用空格隔開,用. 結(jié)束輸入。 -*/#include <stdio.h>#include "string.h"void bky(); int fun(char *c,int status) /*Begin*/ if (*c= ' ') return 1;else if(status && *c <= 'z' && *c >= 'a')*c += 'A' - 'a're

10、turn 0; /* End */ main() int flag=1; char ch; printf("請輸入一字符串,用點號結(jié)束輸入!n") ; do ch=getchar(); flag=fun(&ch, flag); putchar(ch); while(ch!='.'); printf("n"); bky(); void bky( ) char s181, ch; unsigned int i, flag = 1; FILE *rf, *wf ; rf = fopen("in.dat", "

11、;r") ; wf = fopen("out.dat", "w") ; fgets(s1, 80, rf) ; for(i = 0 ; i < strlen(s1); i+) ch = s1i ; flag = fun(&ch, flag) ; s1i = ch ; fprintf( wf,"%s", s1 ); fclose(rf) ; fclose(wf) ; /*-【程序設計】-功能:編寫一個函數(shù),該函數(shù)可以統(tǒng)計一個長度為2的字符 串在另一個字符串中出現(xiàn)的次數(shù)。例如:假定輸入的字符串為:asdasasdf

12、gasdaszx67asdmklo, 字符串為:as,則應輸出6。-*/#include<stdio.h>#include<string.h>#include<conio.h>void bky(); int fun(char *str,char *substr) /*Begin*/ int i,n=0; for(i=0;i<=strlen(str)-2;i+) if(stri=substr0)&&(stri+1=substr1) n+; return n; /* End */main() char str81,substr3; int

13、n; printf("輸入主字符串: "); gets(str); printf("輸入子字符串: "); gets(substr); puts(str); puts(substr); n=fun(str,substr); printf("n=%dn",n); bky();void bky() FILE *IN,*OUT; int n; char i200; IN=fopen("in.dat","r"); if(IN=NULL) printf("Read FILE Error"

14、;); OUT=fopen("out.dat","w"); if(OUT=NULL) printf("Write FILE Error"); fscanf(IN,"%s",i); n=fun(i,"as"); fprintf(OUT,"%d",n); fclose(IN); fclose(OUT);/*-【程序改錯】-題目:下列給定程序中,fun函數(shù)的功能是:分別統(tǒng)計字符串中大寫字母和小寫字母的個數(shù)。例如,給字符串s輸入:AAaBBb123CCccccd,則應輸出結(jié)果:大寫字

15、母個數(shù)=6,小寫字母個數(shù) =7。-*/#include <stdio.h>void fun (char s) /*ERROR*/int i,upper=0,lower=0; int i=0,upper=0,lower=0; while (si) if (si>='A'&& si<='Z')/*ERROR*/upper+1; upper+;upper=upper+1;+upper;if (si>='a'&& si<='z')/*ERROR*/ lower+1;low

16、er+;+lower;lower=lower+1;i+;printf("n 大寫字母 個數(shù)= %d 小寫字母個數(shù) = %dn", upper, lower); main() char s100; printf("n請輸入一個字符串: "); gets(s);puts(s); fun(s);/*-【程序填空】-功能:以下程序以每行4個數(shù)據(jù)的形式輸出a數(shù)組。-*/#include <stdio.h>#define N 20int main() int aN,i; for(i=0;i<N;i+) /*FILL*/scanf("%d&

17、quot;,_&ai_); for(i=0;i<N;i+)/*FILL*/if(_i%4=00= i%4_)/*FILL*/_ printf("n")_;printf("%3d",ai);printf("n");return 0;*3=8*/*-【程序設計】-功能:編寫函數(shù)求表達式的和(n的值由主函數(shù)輸入)。 1-1/2+1/3-1/4+.+1/m例如:當n=20時,表達式的值為0.668771。-*/#include "stdio.h"double sum(int n) /*Begin*/ doub

18、le s=0; int i,k=1; for(i=1;i<=n;i+) s=s+k*1.0/i; k=-k; return(s); /* End */main() int n; void TestFunc(); scanf("%d",&n); printf("sum=%fn",sum(n); TestFunc(); void TestFunc() FILE *IN,*OUT; int n; int i10; double o; IN=fopen("in.dat","r"); if(IN=NULL) p

19、rintf("Read File Error"); OUT=fopen("out.dat","w"); if(OUT=NULL) printf("Write File Error"); for(n=0;n<5;n+) fscanf(IN,"%d",&in); for(n=0;n<5;n+) o = sum(in); fprintf(OUT,"%fn",o); fclose(IN); fclose(OUT);/*-【程序設計】-功能:從鍵盤上輸入任意實數(shù)x,

20、求出其所對應的函數(shù)值。 z=(x-4)的二次冪(x>4) z=x的八次冪(x>-4) z=z=4/(x*(x+1)(x>-10) z=|x|+20(其他)-*/#include <math.h>#include <stdio.h>void bky(); float y(float x) /*Begin*/ float z; if(x>4) z=sqrt(x-4); else if(x>-4) z=pow(x,8); else if(x>-10) z=4/(x*(x+1); else z=fabs(x)+20; return(z); /

21、* End */main() float x; scanf("%f",&x); printf("y=%fn",y(x); bky();void bky() FILE *IN,*OUT; int n; float i; float o; IN=fopen("in.dat","r"); if(IN=NULL) printf("Read FILE Error"); OUT=fopen("out.dat","w"); if(OUT=NULL) printf

22、("Write FILE Error"); for(n=0;n<10;n+) fscanf(IN,"%f",&i); o=y(i); fprintf(OUT,"%fn",o); fclose(IN); fclose(OUT);/*-【程序填空】-功能:請編寫一個函數(shù)fun,將字符數(shù)組ss中字符串中所有下標為奇數(shù)位置上的字母轉(zhuǎn)換為大寫(若該位置上不是字母,則不轉(zhuǎn)換)。-*/#include<stdio.h>#include<string.h>void fun(char ss)int i,d;d=st

23、rlen(ss);/*FILL*/for(i=1;i<d; _ i+=2i=i+2i=2+i_) if(ssi>='a'&&ssi<='z')/*FILL*/_ ssi=ssi-32_;main() char a80; printf("給字符串賦值:n"); gets(a); printf("輸出原字符串:n"); puts(a); /*FILL*/_ fun(a)_; printf("輸出原字符串:n"); puts(a);/*-【程序改錯】-功能:編寫函數(shù)fun,求

24、兩個整數(shù)的最小公倍數(shù),然后用主 函數(shù)main()調(diào)用這個函數(shù)并輸出結(jié)果,兩個整數(shù)由 鍵盤輸入。-*/#include "stdio.h"main() unsigned int m,n,q; printf("m,n="); scanf("%d,%d",&m,&n); /*ERROR*/ q=fun(m,n); q=fun(m,n); printf("p(%d,%d)=%d",m,n,q); int fun(int m,int n) int i; /*ERROR*/ if (m=n) if (m<

25、n) i=m; m=n; n=i; for(i=m;i<=m*n;i+=m) /*ERROR*/ if(i%n=1) if(i%n=0) return(i);*4=13*/* 請編寫一個函數(shù)unsigned fun (unsigned w),w是一個大于10的無符號整數(shù),若w是n(n2)位的整數(shù),函數(shù)求出w的后n-1位的數(shù)作為函數(shù)值返回。 例如:w值為5923,則函數(shù)返回923;w值為923,則函數(shù)返回23。 注意:部分源程序保存在文件prog.c中。 請勿改動主函數(shù)main和其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入你編寫的若干語句。*/#include <conio.h

26、>#include <stdio.h>#include <windows.h>unsigned fun ( unsigned w ) /* Begin */int i, j, sqr = 1;unsigned result;char * str,ch5;str=ch;for (i = 1; (i < 6) && (w >= 1); i+) stri - 1 = '0' + w % 10; w /= 10;stri - 1 = 0;result = str0 - '0'for (j = 1; j <

27、i - 2; j+ ) sqr *= 10; result += (strj - '0') * sqr;return result; /* End */void NONO( )/* 請在此函數(shù)內(nèi)打開文件,輸入測試數(shù)據(jù),調(diào)用 fun 函數(shù), 輸出數(shù)據(jù),關閉文件。 */ unsigned x ; int i ; FILE *rf, *wf ; rf = fopen("bc5.in", "r") ; wf = fopen("bc5.out", "w") ; for(i = 0 ; i < 20 ;

28、i+) fscanf(rf, "%u", &x) ; fprintf(wf, "%un", fun(x) ; fclose(rf) ; fclose(wf) ;main( ) unsigned x; system("cls"); printf ( "Enter a unsigned integer number : " ); scanf ( "%u", &x ); printf ( "The original data is : %un", x ); if (

29、 x < 10 ) printf ("Data error !"); else printf ( "The result : %un", fun ( x ) ); NONO( );/* 函數(shù)fun的功能是:將s所指字符串中ASCII值為偶數(shù)的字符刪除,串中剩余字符形成一個新串放在t所指的數(shù)組中。 例如,若s所指字符串中的內(nèi)容為:"ABCDEFG12345",其中字符B的ASCII碼值為偶數(shù)、字符2的ASCII碼值為偶數(shù)、都應當刪除,其他依次類推。最后t所指的數(shù)組中的內(nèi)容是:"ACEG135"。 注意:部分源程

30、序存在文件prog.c中。 請勿改動主函數(shù)main和其他函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入你編寫的若干語句。*/#include <conio.h>#include <stdio.h>#include <string.h>#include<windows.h>void fun(char *s,char t) /* Begin */int i,slenth,n=0; slenth=strlen(s); for(i=0;i<slenth;i+) if(si%2!=0) tn+=si; tn='0' /* End */

31、NONO ( )/* 本函數(shù)用于打開文件,輸入數(shù)據(jù),調(diào)用函數(shù),輸出數(shù)據(jù),關閉文件。 */ char s100, t100 ; FILE *rf, *wf ; int i ; rf = fopen("bc04.dat", "r") ; wf = fopen("bc04.out", "w") ; for(i = 0 ; i < 10 ; i+) fscanf(rf, "%s", s) ; fun(s, t) ; fprintf(wf, "%sn", t) ; fclose(

32、rf) ; fclose(wf) ;main() char s100,t100; system("cls"); printf("nPlease enter string S:");scanf("%s",s); fun(s,t); printf("nThe result is: %sn",t); NONO();/*- 【程序改錯】-功能:一個整數(shù),它加上100后是一個完全平方數(shù),再加上168又 是一個完全平方數(shù),請問該數(shù)是多少?-*/#include "stdio.h"#include "

33、;math.h"main() long int i,x,y,z; /*ERROR*/ for (i=1;i<100000;i+) for (i=1;i<100000;i+) /*ERROR*/ x=sqrt(i+100) x=sqrt(i+100); y=sqrt(i+268); /*ERROR*/ if(x*x=i+100|y*y=i+268) if(x*x=i+100&&y*y=i+268) printf("n%ldn",i); *-【程序填空】-功能:輸出1到100之間每位數(shù)的乘積大于每位數(shù)的和的數(shù)。例如:數(shù)字26,數(shù)位上數(shù)字的乘

34、積12大于數(shù)字之和8。-*/#include "stdio.h"main() int n,k=1,s=0,m; for(n=1;n<=100;n+) k=1; s=0; /*FILL*/ _m=n_ ; /*FILL*/ while( _m>0_ ) k*=m%10; s+=m%10; /*FILL*/ _m=m/10_; if(k>s) printf("%d ",n); *5=11*/*-【程序設計】-功能:計算n門課程的平均值,計算結(jié)果作為函數(shù)值返回。例如:若有5門課程的成績是:92,76,69,58,88, 則函數(shù)的值為76.60

35、0000。-*/ #include <stdio.h>void TestFunc(); float fun(int a,int n) /*Begin*/ int i; float y=0; for(i=0;i<n;i+) y+=ai; y=y/n; return y; /* End */ main() int a=92,76,69,58,88; printf("y=%fn",fun(a,5); TestFunc();void TestFunc() FILE *IN,*OUT; int iIN10,i,j; float fOUT; IN=fopen(&quo

36、t;in.dat","r"); if(IN=NULL) printf("Please Verify The Currernt Dir.it May Be Changed"); OUT=fopen("out.dat","w"); if(OUT=NULL) printf("Please Verify The Current Dir. it May Be Changed"); for(j=0;j<5;j+) for(i=0;i<5;i+) fscanf(IN,"%d&q

37、uot;,&iINi); fOUT=fun(iIN,5); fprintf(OUT,"%fn",fOUT); fclose(IN); fclose(OUT);/*-【程序設計】-功能:從鍵盤為一維整型數(shù)組輸入10個整數(shù),調(diào)用fun函數(shù) 找出其中最小的數(shù),并在main函數(shù)中輸出。-*/#include <stdio.h> void TestFunc(); int fun(int x,int n) /*Begin*/ int min,i;min=x0;for(i=1;i<n;i+)if(xi<min) min=xi;return min; /*

38、End */ main() int a10,i,min; for(i=0;i<10;i+) scanf("%d",&ai); for(i=0;i<10;i+) printf("%3d",ai); printf("n"); min=fun(a,10); printf("%dn",min); TestFunc();void TestFunc() FILE *IN,*OUT; int iIN10,i; int iOUT,iCOUNT; IN=fopen("in.dat","

39、;r"); if(IN=NULL) printf("Please Verify The Currernt Dir.it May Be Changed"); OUT=fopen("out.dat","w"); if(OUT=NULL) printf("Please Verify The Current Dir. It May Be Changed"); for(i=0;i<5;i+) for(iCOUNT=0;iCOUNT<10;iCOUNT+) fscanf(IN,"%d"

40、,&iINiCOUNT); iOUT=fun(iIN,10); fprintf(OUT,"%dn",iOUT); fclose(IN); fclose(OUT);/*-【程序改錯】-題目:打印出以下的楊輝三角形(要求打印出10行),請改正程序中的錯誤,使它能得出正確 的結(jié)果。1 1 11 2 11 3 3 11 4 6 4 11 51010 5 11 61520 15 6 11 72135 35 21 7 11 8 285670 5628 8 11 93684 126 1268436 9 1-*/#include "stdio.h"#define

41、 N 10main()int aNN;int i,j;for(i=0;i<10;i+)/*ERROR*/a11=1;a0i=1;【參考答案】ai0=1;aii=1;aii=1;ai0=1;ai0=aii=1;aii=ai0=1;for(i=2;i<10;i+)/*ERROR*/for(j=1;j<10;j+)【參考答案】for(j=1;j<i;j+)for(j=1;i>j;j+)/*ERROR*/aij=aij-1+aij;【參考答案】aij=ai-1j-1+ai-1j;for(i=0;i<10;i+) /*打印楊輝三角形*/for(j=0;j<=i;j+)printf("%6d",aij);

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論