程序設計題庫.doc_第1頁
程序設計題庫.doc_第2頁
程序設計題庫.doc_第3頁
程序設計題庫.doc_第4頁
程序設計題庫.doc_第5頁
已閱讀5頁,還剩8頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

編程題編程題要求:注意: 部分源程序存在文件PROG1.C中。請在/*begin*/ 與 /*end*/之間填入你編寫的若干語句。請勿改動其它位置的任何內容。main()函數(shù)中的最后一行以及main()函數(shù)后面的內容,考生不必閱讀,但千萬不要對這些內容作任何改動。1、將兩個兩位數(shù)的正整數(shù)a、b合并形成一個整數(shù)放在c中。合并的方式是:將a數(shù)的十位和個位數(shù)依次放在c數(shù)的千位和十位上,b數(shù)的十位和個位數(shù)依次放在c數(shù)的百位和個位上。例如,當a=45,b=12。調用該函數(shù)后,c=4152。源文件: #include #include long fun(int a, int b) long c; /*begin*/ int i,j,m,n; i=a%10;j=a/10;m=b%10;n=b/10; c=j*1000+n*100+i*10+m; /*end*/ return c; main() int a,b; long c; printf(Input a, b:); scanf(%d,%d, &a, &b); c = fun(a, b); printf(The result is: %ldn, c); NONO(); NONO ( ) FILE *rf, *wf ; int i, a,b ; long c ; rf = fopen(in1.dat, r) ; wf = fopen(out1.dat,w) ; for(i = 0 ; i 10 ; i+) fscanf(rf, %d,%d, &a, &b) ; c = fun(a, b) ; fprintf(wf, a=%d,b=%d,c=%ldn, a, b, c) ; fclose(rf) ; fclose(wf) ; 2、按下面的公式求sum的值。sum = 1 - 2 + 3 - 4 + 5 - 6 + + 99 - 100源文件: #include stdio.h #include math.h #include conio.h #include stdlib.h main() int sum; /*begin*/ int i,b;sum=0; for(i=1;i=100;i+=2) b=-1*(i+1); sum+=i+b; /*end*/ printf(sum=%dn,sum); NONO(sum); NONO( int x) FILE *f; f=fopen(out1.dat,w); fprintf(f,sum=%dn,x); fclose(f); 3、按下面的公式求sum的值。 1 1 1 1 sum = 1 + + + + + 2 3 4 100源文件: #include stdio.h #include math.h #include conio.h #include stdlib.h main() double sum; /*begin*/ int i;float t;sum=1; for(i=2;i=100;i+) t=1.0/i; sum=sum+t; /*end*/ printf(sum=%.3fn,sum); NONO(sum); NONO( double x) FILE *f; f=fopen(out1.dat,w); fprintf(f,sum=%.3fn,x); fclose(f); 4、求指定字符在字符串中出現(xiàn)的次數(shù)并輸出。 例如,當字符串為This Is a c Program,指定字符為a時 則應輸出:Result is: 2源文件: #include #include int fun(char str1,char ch) /*begin*/ int i,n=0; for(i=0;str1i!=0;i+) if(str1i=ch) n+; return(n); /*end*/ main() char str180=This Is a c Program,ch=a; int count; printf(String is: %sn,str1); printf(char is: %cn,ch); count=fun(str1,ch); printf(Result is: %dn,count); nono(count); nono(int count) FILE *f; f=fopen(out1.dat,w); fprintf(f,Result is :%dn,count); fclose(f); 5、求3*3矩陣的第0行元素的和并輸出。 例如,當矩陣為: 1 2 3 4 5 6 7 8 9 則第0行元素的和為:6源文件: #include #include int fun(int a33) /*begin*/ int i,p=0,sum=0; for(i=0;i3;i+) sum+=api; return(sum); /*end*/ main() int a33=1,2,3,4,5,6,7,8,9; int i,j,sum; printf(array is:n); for(i=0;i3;i+) for(j=0;j=1e-6); /*end*/ printf(sum=%.3fn,sum); NONO(sum); NONO( double x) FILE *f; f=fopen(out1.dat,w); fprintf(f,sum=%.3fn,x); fclose(f); 7、將字符串倒序存放并輸出。 例如,當字符串為This Is a c Program 輸出:margorP c a sI sihT源文件: #include #include void fun(char str1) /*begin*/ int i,j;char t; for(i=0;str1i!=0;i+)j=i; i=0; do t=str1i; str1i=str1j; str1j=t; i+; j-; while(j=i); /*end*/ main() char str180=This Is a c Program; printf(String is: %sn,str1); fun(str1); printf(Result is: %sn,str1); nono(str1); nono(char str1) FILE *f; f=fopen(out1.dat,w); fprintf(f,%sn,str1); fclose(f); 8、將字符串中的所有小寫字母轉換為大寫字母并輸出。 例如,當字符串為This Is a c Program 程序的輸出應為:THIS IS A C PROGRAM源文件: #include #include void fun(char str1) /*begin*/ int i; for(i=0;str1i!=0;i+) if(str1i=a&str1i=z) str1i-=32; /*end*/ main() char str180=This Is a c Program; printf(String is: %sn,str1); fun(str1); printf(Result is: %sn,str1); nono(str1); nono(char str1) FILE *f; f=fopen(out1.dat,w); fprintf(f,%sn,str1); fclose(f); 9、統(tǒng)計字符串中的所有小寫字母的個數(shù)并輸出。 例如,當字符串為This Is a c Program 輸出:Result is:12源文件: #include #include int fun(char str1) /*begin*/ int i,n=0; for(i=0;str1i!=0;i+) if(str1i=a&str1i=z) n+; return(n); /*end*/ main() char str180=This Is a c Program; int count; printf(String is: %sn,str1); count=fun(str1); printf(Result is: %dn,count); nono(count); nono(int count) FILE *f; f=fopen(out1.dat,w); fprintf(f,The sum is :%dn,count); fclose(f); 10、統(tǒng)計字符串中的所有元音字母a的個數(shù)并輸出。 例如,當字符串為This Is a c Program 輸出:Result is: 2源文件: #include #include int fun(char str1) /*begin*/ int i,n=0; for(i=0;str1i!=0;i+) if(str1i=a) n+; return(n); /*end*/ main() char str180=This Is a c Program; int count; printf(String is: %sn,str1); count=fun(str1); printf(Result is: %dn,count); nono(count); nono(int count) FILE *f; f=fopen(out1.dat,w); fprintf(f,The sum is :%dn,count); fclose(f); 11、將字符串1的第1,3,5,7,9,.位置的字符復制到字符串2并輸出。 例如,當字符串1為This Is a c Program 則字符串2為hsI rga源文件: #include #include void fun(char str1,char str2) /*begin*/ int i,j=0; for(i=1;str1i!=0;i+=2) str2j=str1i;j+; str2j=0; /*end*/ main() char str180=This Is a c Program,str280; printf(String is: %sn,str1); fun(str1,str2); printf(Result is: %sn,str2); nono(str2); nono(char str1) FILE *f; f=fopen(out1.dat,w); fprintf(f,%sn,str1); fclose(f); 12、將字符串2連接到字符串1的后面并輸出。 例如,當字符串1為This Is a ,字符串2為c Program 則輸出:This Is a c Program源文件: #include #include void fun(char str1,char str2) /*begin*/ int i=0,j=0; for(i=0;str1i!=0;i+); for(j=0;str2j!=0;j+) str1i=str2j;i+; str1i=0; /*end*/ main() char str180=This Is a ,str280=c Program; printf(String1 is: %sn,str1); printf(String2 is: %sn,str2); fun(str1,str2); printf(Result is: %sn,str1); nono(str1); nono(char str1) FILE *f; f=fopen(out1.dat,w); fprintf(f,%sn,str1); fclose(f); 13、求字符串的長度并輸出。 例如,當字符串1為This Is a c Program 則應輸出:Result is: 19源文件: #include #include int fun(char str1) /*begin*/ int i,n; for(i=0;str1i!=0;i+) n=i+1; return(n); /*end*/ main() char str180=This Is a c Program; int count; printf(String is: %sn,str1); count=fun(str1); printf(Result is: %dn,count); nono(count); nono(int count) FILE *f; f=fopen(out1.dat,w); fprintf(f,The sum is :%dn,count); fclose(f); 14、求指定字符在字符串中第一次出現(xiàn)的位置并輸出。 例如,當字符串為This Is a c Program,指定字符為a時 則應輸出:Result is: 8源文件: #include #include int fun(char str1,char ch) /*begin*/ int i,n=0; for(i=0;str1i!=0;i+) if(str1i=ch) n=i; if(n!=0)break; return(n); /*end*/ main() char str180=This Is a c Program,ch=a; int posi; printf(String is: %sn,str1); printf(char is: %cn,ch); posi=fun(str1,ch); printf(Result is: %dn,posi); nono(posi); nono(int posi) FILE *f; f=fopen(out1.dat,w); fprintf(f,The sum is :%dn,posi); fclose(f); 15、將字符串中的所有字符a替換成A,其余的不變;并輸出。 例如,當字符串為This Is a c Program, 則輸出:This Is A c ProgrAm源文件: #include #include void fun(char str1) /*begin*/ int i; for(i=0;str1i!=0;i+) if(str1i=a) str1i-=32; /*end*/ main() char str180=This Is a c Program; printf(String is: %sn,str1); fun(str1); printf(Result is: %sn,str1); nono(str1); nono(char str1) FILE *f; f=fopen(out1.dat,w); fprintf(f,%sn,str1); fclose(f); 16、按下面的公式求sum的近似值,直到最后一項的項值小于1e-6為止。 1 1 1 1 1 sum = 1 + + + + + + 3*3 5*5 7*7 9*9 (2n-1)(2n-1)源文件: #include stdio.h #include math.h #include stdlib.h main() double sum=0; float i; /*begin*/ float t; i=1; dot=1.0/(2*i-1)*(2*i-1); sum+=t; i+; while(t=1e-6); /*end*/ printf(sum=%.3fn,sum); NONO(sum); NONO( double x) FILE *f; f=fopen(out1.dat,w); fprintf(f,sum=%.3fn,x); fclose(f); 17、將一個4位的整數(shù)m拆開,然后按相反順序輸出,每輸出一位數(shù)其后留2個空格。例如,如果m=1234,則程序的輸出結果應為:m=1234,4 3

溫馨提示

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

評論

0/150

提交評論