




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、計(jì)算機(jī)二級(jí)C語(yǔ)言題庫(kù)之程序填空 找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個(gè)整數(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);調(diào)用函數(shù)f,將一個(gè)整數(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);調(diào)用函數(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);調(diào)用find函數(shù)在輸入的字符串中查找是否出現(xiàn)"the"這個(gè)單詞。如果查到返回出現(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);輸入的一個(gè)小寫(xiě)字母,將字母循環(huán)后移5個(gè)位置后輸出。例如:"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
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);對(duì)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);輸入三個(gè)整數(shù),按由小到大的順序輸出這三個(gè)數(shù)。#include <s
10、tdio.h>void swap(_1_) / int *pa, int *pb /*交換兩個(gè)數(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);調(diào)用函數(shù)f,去除數(shù)組中的負(fù)數(shù),輸入數(shù)組x7,輸出結(jié)果為: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");調(diào)用函數(shù)f計(jì)算代數(shù)多項(xiàng)式1.1+2.2*x+3.3*x*x+4.4*x*x*x+5.5*x*x*x*x當(dāng)x=1.7時(shí)的值。#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)計(jì)字符串中英文字母、數(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)計(jì)字母?jìng)€(gè)數(shù)*/n0+; else if (_2_) /*統(tǒng)計(jì)數(shù)字個(gè)數(shù)*/ / ai>='0' && ai<='9'n1+;elsen2+;for(i=0;i<
15、;3;i+) printf("%dn",ni);將輸入的十進(jìn)制整數(shù)n通過(guò)函數(shù)DtoH函數(shù)轉(zhuǎn)換為十六進(jìn)制數(shù),并將轉(zhuǎn)換結(jié)果以字符串形式輸出。(例如:輸入十進(jìn)制數(shù)79,將輸出十六進(jìn)制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);將輸入的十 進(jìn)制正整數(shù)n通過(guò)函數(shù)Dec2Bin轉(zhuǎn)換為二進(jìn)制數(shù),并將轉(zhuǎn)換結(jié)果輸出。#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項(xiàng)均為1,此后各項(xiàng)值均為該項(xiàng)前二項(xiàng)之和。計(jì)算數(shù)列第30項(xiàng)的值。#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);該程序計(jì)算四位學(xué)生的平均成績(jī),保存在結(jié)構(gòu)中,然后列表輸出這些學(xué)生的信息。#include <stdio.h>struct STUDENT char name16;int math;int english;int computer;int average;void GetAverage(struct STUDENT *pst) /*
19、計(jì)算平均成績(jī) */ 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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024-2025學(xué)年高中生物第2單元第2章第1節(jié)核酸的結(jié)構(gòu)和功能教案中圖版必修1
- 搪瓷保溫杯的優(yōu)勢(shì)與選購(gòu)指南考核試卷
- 方便面餅的復(fù)水性測(cè)試與品質(zhì)評(píng)價(jià)考核試卷
- 科技引領(lǐng)的商業(yè)運(yùn)輸領(lǐng)域中如何更好地利用綠色物流和新能源自卸車(chē)
- 電商平臺(tái)的物流信息系統(tǒng)建設(shè)
- 科技助力傳統(tǒng)文化煥發(fā)新活力
- 時(shí)尚產(chǎn)品設(shè)計(jì)實(shí)踐考核試卷
- 智慧路燈合同范本
- 摩托車(chē)點(diǎn)火系統(tǒng)原理與維修考核試卷
- 電子商務(wù)平臺(tái)戰(zhàn)略運(yùn)營(yíng)解析與盈利路徑探討
- Q∕GDW 11612.2-2018 低壓電力線高速載波通信互聯(lián)互通技術(shù)規(guī)范 第2部分:技術(shù)要求
- 公司辦公室5S管理規(guī)定(實(shí)用含圖片)
- (完整版)餐飲員工入職登記表
- 智能化工程施工工藝圖片講解
- 人教版小學(xué)五年級(jí)數(shù)學(xué)下冊(cè)教材解讀
- 2022年最新蘇教版五年級(jí)下冊(cè)科學(xué)全冊(cè)教案
- 咳嗽與咳痰課件
- 小學(xué)四年級(jí)數(shù)學(xué)奧數(shù)應(yīng)用題100題
- 綜合布線驗(yàn)收?qǐng)?bào)告材料
- 《初三心理健康教育》ppt課件
- 重慶鐵塔公司配套設(shè)備安裝施工服務(wù)技術(shù)規(guī)范書(shū)
評(píng)論
0/150
提交評(píng)論