計算機二級C語言題庫之程序填空_第1頁
計算機二級C語言題庫之程序填空_第2頁
計算機二級C語言題庫之程序填空_第3頁
計算機二級C語言題庫之程序填空_第4頁
計算機二級C語言題庫之程序填空_第5頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、計算機二級C語言題庫之程序填空 找Armstrong(水仙花)數(shù):371=3*3*3+7*7*7+1*1*1#include <stdio.h>#include<math.h>void main() int i,a,b,c;for(i=100;i<=999;i+) a=i/100;_1_ / b=i%100/10;c=i%10;if (_2_) / a*a*a+b*b*b+c*c*c = = i printf("%d is a Armstrong number!n",i);輸入1個整數(shù)后,

2、輸出該數(shù)的位數(shù)。(例:輸入3214則輸出4,輸入-23156則輸出5)。#include <stdio.h>void main() int n,k=0;scanf("%d",&n);while( _1_ ) / n!=0k+;_2_; / n=n/10printf("%dn",k);求輸入的整數(shù)各位數(shù)字之和,如輸入234則輸出9,輸入-312則輸出6。#include <stdio.h>#include <math.h>vo

3、id main()int n,s=0;scanf("%d",&n);_ 1 _ / if (n<0) n=-n;while(n!=0) _ 2 _ / s+=n%10;n=n/10;printf("%dn",s);調用函數(shù)f,將一個整數(shù)首尾倒置。例如:若程序輸入12345,則輸出54321;若程序輸入-34567,則輸出-76543。#include <stdio.h>#include <math.h>long f(long n) lon

4、g m,y=0; m=fabs(n);while(m!=0) y=y*10+m%10; _1_ / m=m/10 ;if(n>=0) return y;else _2_ / return -y ;void main()printf("%ldt",f(12345); printf("%ldn",f(-34567);調用函數(shù)f,從字符串中刪除所有的數(shù)字字符。#include <stdio.h>#include <string.h>#include &

5、lt;ctype.h>void f(char *s) int i=0;while(si!='0')if(isdigit(si) _1_(s+i,s+i+1); / strcpy_2_ i+; / elsevoid main() char str80; gets(str); f(str); puts(str);調用find函數(shù)在輸入的字符串中查找是否出現(xiàn)"the"這個單詞。如果查到返回出現(xiàn)的次數(shù),如果未找到返回0。#include <stdio.h>int find(char *str)

6、 char *fstr="the"int i=0,j,n=0; while (stri!='0')for(_1_) / j=0; j<3; j+if (strj+i!=fstrj) break;if (_2_) n+; / j>=3i+;return n;void main() char a80;gets(a);printf("%d",find(a);輸入的一個小寫字母,將字母循環(huán)后移5個位置后輸出。例如:"a"變成&q

7、uot;f","w"變成"b"。#include <stdio.h>void main() char c;c=getchar();if(_1_) / c>='a'&&c<='u'c=c+5;elseif (c>='v' && c<='z&#3

8、9;)_2_ / c=(c-'a'+5)%26+'a'putchar(c);將字符串s中所有的字符'c'刪除。#include <stdio.h>void main() char s80;int i,j;gets(s);for(i=j=0; _1_; i+) / si != '0'if(si != 'c') sj=si;_2_ / j+; sj='0'puts(s);對x=1,

9、2,10,求f(x)=x*x-5*x+sin(x)的最大值。#include <stdio.h>#include <math.h>#define f(x) x*x-5*x+sin(x)void main() int x; float max;_1_ / max=f(1);for(x=2;x<=10;x+)_2_ / if (f(x)>max) max=f(x);printf("%fn",max);輸入三個整數(shù),按由小到大的順序輸出這三個數(shù)。#include <s

10、tdio.h>void swap(_1_) / int *pa, int *pb /*交換兩個數(shù)的位置*/int temp;temp = *pa;*pa = *pb;*pb = temp;void main() int a,b,c,temp;scanf("%d%d%d",&a,&b,&c);if(a>b)swap(&a,&b);if(b>c)swap(&b,&c);if(_2_) / if ( a&

11、gt;b )swap(&a,&b);printf("%d,%d,%d",a,b,c);調用函數(shù)f,去除數(shù)組中的負數(shù),輸入數(shù)組x7,輸出結果為:1 3 4 6#include <stdio.h> / 數(shù)組元素的刪除void f(int *a,int *m) int i, j ;for(i=0;i<*m;i+)if(ai<0) for(j=i-;j<*m-1;j+) aj=aj+1;_1_; / *m = *m-1;void main() int i,n=7,x

12、7=1,-2,3,4,-5,6,-7;_2_; / f (x, &n) ;for(i=0;i<n;i+) printf("%5d",xi);printf("n");調用函數(shù)f計算代數(shù)多項式1.1+2.2*x+3.3*x*x+4.4*x*x*x+5.5*x*x*x*x當x=1.7時的值。#include <stdio.h>float f(float, float*, int);void main() float b5=1.1, 2.2, 3.3, 4.4, 5.5 ;

13、printf("%fn", f(1.7,b,5) );float f( _1_ ) / float x, float *a, int n float y=a0, t=1; int i;for(i=1; i<n; i+) t=t*x; y=y+ai*t; _2_ / return y;分別統(tǒng)計字符串中英文字母、數(shù)字、和其他字符出現(xiàn)的次數(shù)。#include <stdio.h>#include <ctype.h>void main() char a80; int n3=0, i; gets(a)

14、 ;_1_ / for ( i=0; ai!='0' i+)if (tolower(ai)>='a' && tolower(ai)<='z') /*統(tǒng)計字母個數(shù)*/n0+; else if (_2_) /*統(tǒng)計數(shù)字個數(shù)*/ / ai>='0' && ai<='9'n1+;elsen2+;for(i=0;i&lt

15、;3;i+) printf("%dn",ni);將輸入的十進制整數(shù)n通過函數(shù)DtoH函數(shù)轉換為十六進制數(shù),并將轉換結果以字符串形式輸出。(例如:輸入十進制數(shù)79,將輸出十六進制4f。)# include <stdio.h># include <string.h>char trans(int x)if(x<10) return '0'+x;else _1_ / return 'a'+x-10;int DtoH(int n,cha

16、r *str)int i=0;while(n!=0)_2_ / stri=trans(n%16);n/=16;i+; return i-1;void main()int i,k,n;char *str; scanf("%d",&n);k=DtoH(n,str);for (i=0;i<=k;i+) printf("%c",strk-i);將輸入的十 進制正整數(shù)n通過函數(shù)Dec2Bin轉換為二進制數(shù),并將轉換結果輸出。#include <stdio.h>void Dec

17、2Bin(int m)int bin32,j;for(j=0;m!=0;j+)binj= _1_; / m%2m=m/2;for( ; j!=0; j- )printf("%d", _2_ ); / binj-1void main()int n;scanf("%d",&n);Dec2Bin(n);數(shù)列的第1、2項均為1,此后各項值均為該項前二項之和。計算數(shù)列第30項的值。#include <stdio.h>_1_ / long f(int n); 或者 long f(int);v

18、oid main() printf("%ldn",f(30) ;long f(int n) if( _2_ ) / n=1 | n=2return 1;elsereturn f(n-1)+f(n-2);該程序計算四位學生的平均成績,保存在結構中,然后列表輸出這些學生的信息。#include <stdio.h>struct STUDENT char name16;int math;int english;int computer;int average;void GetAverage(struct STUDENT *pst) /*

19、計算平均成績 */ int sum=0;sum = _1_; / pst->math+pst->english+pst->computerpst->average = sum/3;void main() int i;struct STUDENT st4="Jessica",98,95,90,"Mike",80,80,90,"Linda",87,76,70,"Peter",90,100,99;for

20、(i=0;i<4;i+) GetAverage(_2_); / st + iprintf("NametMathtEnglishtComputAveragen");for(i=0;i<4;i+) printf("%st%dt%dt%dt%dn",,sti.math,sti.english,puter,sti.average);輸入m、n(要求輸入數(shù)均大于0)。輸出它們的最大公約數(shù)。#include<stdio.h>void main() int m, n, k;while ( scanf("%d%d", &m, &n), _1_ ); / m<=0|n<=0for (_2_ ; n%k!=0 | m%k!=0 ; k-) ; / k=m>n?n:mprintf("%dn"

溫馨提示

  • 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

提交評論