C語言理論編程題試題庫修訂版_第1頁
C語言理論編程題試題庫修訂版_第2頁
C語言理論編程題試題庫修訂版_第3頁
C語言理論編程題試題庫修訂版_第4頁
C語言理論編程題試題庫修訂版_第5頁
已閱讀5頁,還剩76頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

計算整數(shù)各位數(shù)字之和#include"stdio.h"intmain(){unsignedinta,ge,shi,bai,sum;scanf("%d",&a);ge=a%10;shi=a/10%10;bai=a/100;sum=ge+shi+bai;printf("%d\n",sum);return0;}輸出三角形#include<stdio.h>intmain(void){printf("****\n");printf("***\n");printf("**\n");printf("*\n");return0;}混合類型數(shù)據(jù)格式化輸入intmain(){doublex,w;inty;z;charscanf("%lf%d%c%lf",&x,&y,&z,&w);printf("%c%d%.2f%.2f",z,y,x,w);;return0}交換a和b的值#include<stdio.h>>stdlib.h#include<intmain(){inta,b;,&b,&a);scanf("%d%d"printf("a=%d,b=%d",a,b);;return0}A乘以B#include<stdio.h>#include<stdlib.h>main()int{inta,b,c;scanf("%d%d",&a,&b);c=a*b;printf("%d",c);return0;}厘米換算英尺英寸#include<stdio.h>>stdlib.h<#includeintmain(){inta,b,c;,&a);scanf("%d"b=(a)/30.48;;c=((a)/30.48-b)*12,b,c);printf("%d%d";return0}然后是幾點#include<stdio.h>>stdlib.h<#includeintmain(){inta,b,c,d;,&a,&b);"%d%d"scanf(c=a/100*60+b+a%;;+c%10060d=c/*printf("%d",d);;return0}是不是太胖了#include<stdio.h>intmain(void){intH;scanf("%d",&H);printf("%.1f",((H-100)*0.9*2));return0;}計算存款利息#include<stdio.h>#include<math.h>intmain(void){doubleyear,interest,rate,money;scanf("%lf%lf%lf",&money,&year,&rate);interest=money*pow(1+rate,year)-money;printf("interest=%.2f",interest);return0;}12:01十二小時制是12:01PM三天打魚兩天曬網(wǎng)#include<stdio.h>intmain(intargc,constchar*argv[]){unsignedintN,n;scanf("%d",&N);n=N%5;switch(n){case1:case2:case3:printf("Fishinginday%d",N);break;case4:case0:printf("Dryinginday%d",N);break;}return0;}判斷輸入的字符是哪種類型#include<stdio.h>intmain(){charc;c=getchar();if(c>='0'&&c<='9')printf("Thisisadigit.");elseif(c>='A'&&c<='Z')printf("Thisisacapitalletter.");elseif(c>='a'&&c<='z')printf("Thisisasmallletter.");elseprintf("Othercharacter.");return0;}計算符號函數(shù)的值#include<stdio.h>>stdlib.h#include<intmain(){intn,sign;,&n);scanf("%d"0)if(n<sign=-1;elseif(n==0)sign=0;elsesign=1;printf("sign(%d)=%d",n,sign);return0;}成績轉(zhuǎn)換#include<stdio.h>#include<stdlib.h>main()int{intn;charx;,&n);scanf("%d"if(n>=90)x='A';)80(n>=ifelsex='B';)70(n>=ifelsex='C';)60(n>=elseifx='D';elsex='E';,x);printf("%c"0;return}intmain(){intn1,n2,y;charx;scanf("%d%c%d",&n1,&x,&n2);switch(x){:'+'casey=n1+n2;printf("%d",y);break;case'-':y=n1-n2;"%d",y);printf(break;case'*':y=n1*n2;printf("%d",y);break;'/':casey=n1/n2;printf("%d",y);break;:case'%'y=n1%n2;"%d"printf(,y);12-24小時制#include<stdio.h>#include<stdlib.h>intmain(){intn1,n2,y1;char*t;scanf("%d:%d",&n1,&n2);if(n1>=0&&n1<12){y1=n1;t="AM";}){(n1==12elseify1=n1;t="PM";}{else;y1=n1-12t="PM";}printf("%d:%d%s",y1,n2,t);return0;}出租車計價#include<stdio.h>>stdlib.h#include<intmain()double{s;t;intintpay;scanf("%lf%d",&s,&t);)if(s<=3.0+2)*pay=+(t/100.55;10)(s<=elseif+;0.552+(t/3.0+(s-10pay=)*else10.0)+(t/)*0.5*(s-513.02+(s-10pay=+printf("%d",pay);;return0}階梯電價#include<stdio.h>#include<stdlib.h>intmain(){doubles;doublepay;scanf("%lf",&s);if(s<0.0));"InvalidValue!"printf(elseif(s<=50.0){*s;0.53pay=printf("cost=%.2lf",pay);}else{);50*(s-pay=*s+printf("cost=%.2lf",pay);};return0}計算工資#include<stdio.h>>stdlib.h<#includeintmain(){inta,b;money;doublescanf("%d%d",&a,&b);if(a>=5){)40if(b<=money=50*b;else*(b-);4050money=1.5+2000.00*}else{)40if(b<=money=30*b;else*(b-40);+money=*}printf("%.2lf",money);;return0}后天#include<stdio.h>stdlib.h>#include<intmain(){inttoday,aft;scanf("%d",&today);;7aft=(today+2)%if(aft==0)printf("7");elseprintf("%d",aft);return0;}輸出N以內(nèi)的所有素數(shù)#include<stdio.h>#include<math.h>intmain(){intN,i,j,flag,count;scanf("%d",&N);count=0;for(i=2;i<=N;i++){flag=1;for(j=2;j<=sqrt(i);j++){if(i%j==0){flag=0;break;}}if(flag==1){跟奧巴馬一起畫方塊#include<stdio.h>intmain(){intn;charc;while(scanf("%d%c",&n,&c)!=EOF){inti,j;if(n%2==0){for(j=0;j<n/2;j++){for(i=0;i<n;i++){printf("%c",c);生成3的乘方表#include<stdio.h>>stdlib.h#include<intmain(){i,n;intx;intscanf("%d",&n);for(i=0;i<=n;i++){x=pow(3,i);,i,x);printf("pow(3,%d)=%d\n"}return0;}#include<stdio.h>#include<stdlib.h>intmain(){i,n;intinta;,E=intA=0,B=,C=,D=;scanf("%d\n",&n);1;i<=n;i++){for(i="%d",&a);scanf(if(a>=90)A++;(a>=elseif80)B++;(a>=if70else)C++;elseif(a>=60)D++;elseE++;}printf("%d%d%d%d%d",A,B,C,D,E);0;return}"%d%d",&n,&k);scanf(intSumA(a,n){t=(x<y?x:y);,&m,&n);scanf("%d%d"#include<stdlib.0;j<i;j++)for(j=while(*s!=0){#include<stdio.for(i=0;a[i]!=;i++){printf("YES\n");scanf("%d",&ns);(*(str+i)!=c)ift=(x<y?x:y);,&a[i][j]);"%d"scanf(N){List[],OddSum(int輸出閏年#include<stdio.h>>stdlib.h#include<intmain(){inti,n;scanf("%d",&n);){2100&&n<=(n>if2000if(n>=2004){4){;i<=n;i+=for(i=2004if((i%4==0&&i%100!=)||i%400)"%d\n",i);}}printf(elseprintf("None");}elseprintf("Invalidyear!");;return0}尋找250#include<stdio.h>>stdlib.h#include<intmain(){intnum,x;inti=1;{do,&num);"%d"scanf(if(num==250){x=i;break;}i++;}while(getchar()!='\n’);//不需要一直輸入printf("%d",x);return0;}最佳情侶身高差#include<stdio.h>#include<stdlib.h>intmain(){charx;doubley;intn,i;doublea[10000];"%d",&n);scanf(for(i=1;i<=n;i++){scanf("%c%lf",&x,&y);//scanf()函數(shù)第一個取字符時,一定取走上一步遺留下的空白字符,很重要)'M'if(x==a[i]=y/1.09;elsea[i]=y*1.09;};i<=n;i++){for(i=1"%.2lf\n",a[i]);printf(}#include<stdio.h>#include<stdlib.h>intmain(){intns;doublesorce[10000],averger;inti;doublemin,max,sum;scanf("%d",&ns);0;i<ns;i++)for(i=scanf("%lf",&sorce[i]);min=sorce[0];max=min;sum=min;for(i=1;i<ns;i++){if(min>sorce[i])min=sorce[i];if(max<sorce[i])max=sorce[i];sum+=sorce[i];}averger=(sum-max-min)/(ns-2.0);printf("%.2lf",averger);return0;}求平方根序列前N項和#include<stdio.h>>stdlib.h#include<#include<math.h>intmain(){n;intinti;doublesum=0.0;scanf("%d",&n);1;i<=n;i++){for(i=sum+=sqrt(i);}printf("sum=%.2lf",sum);return0;}猴子吃桃問題#include<stdio.h>>stdlib.h#include<intmain(){intN;intns=1;i;int,&N);"%d"scanf(for(i=1;i<N;i++){ns=2*(ns+1);//算法1+3+5+。。。+(s+1)。。。}printf("%d",ns);;return0}求分數(shù)序列前N項和#include<stdio.h>stdlib.h>#include<intmain(){intN;inti;//N=441,t;,fm=2fz=doubledoubleret=1.0*fz/fm;scanf("%d",&N);1;i<N;i++){for(i=t=fz;fz+=fm;fm=t;ret+=(1.0*fz/fm);}printf("%.2lf",ret);return0;}時,fz超過int求給定精度的簡單交錯序列部分和#include<stdio.h>#include<stdlib.h>>math.h#include<intmain(){doubleeps;doublesum=0,f=1;1;intfm=scanf("%lf",&eps);while(fabs(1.0/fm)>eps){sum+=(f/fm);fm+=3;//f=-f;出循環(huán)}sum+=(f/fm);printf("sum=%.6lf",sum);return0;}不能用fm=-fm,因為fm變號后為-4,+3不能跳打印九九口訣表#include<stdio.h>>stdlib.h#include<intmain(){inti,j;intN;scanf("%d",&N);;i<=N;i++){1for(i=for(j=1;j<=i;j++){printf("%d*%d=%-4d",j,i,i*j);});"\n"printf(}return0;}統(tǒng)計素數(shù)并求和#include<stdio.h>#include<stdlib.h>intmain(){intM,N;inti;intns=0,sum=;scanf("%d%d",&M,&N);(;M<=N;M++){forif(M==2){//2ns++;sum+=M;}for(i=2;i<M;i++){)0(M%i==ifbreak;if(i==(M-1)){ns++;sum+=M;}}}"%d%d"printf(,ns,sum);是特例,須特別考慮輸出三角形字符陣列#include<stdio.h>>stdlib.h#include<intmain(){intn;;charc='A'-1i,j;intscanf("%d",&n);for(i=1;i<=n;i++){for(j=1;j<=(n+-i);j++){c++;printf("%c",c);}printf("\n");}return0;}特殊a串數(shù)列求和#include<stdio.h>>stdlib.h#include<#include<math.h>intmain(){inta,n;;,x=ints=0inti;scanf("%d%d",&a,&n);for(i=1;i<=n;i++){);x=(a+x*10s+=x;}printf("s=%d",s);;return0}約分最簡分式#include<stdio.h>>stdlib.h#include<#include<math.h>intmain(){intfz,fm;i;int,&fz,&fm);scanf("%d/%d"for(i=2;i<=fz;){if(fz%i==0&&fm%i==){fz/=i;fm/=i;}elsei++;}printf("%d/%d",fz,fm);0;return}求二維數(shù)組的最大值和最小值#include<stdio.h>#defineN3intmain(){inta[N][N]={0};inti,j;intmax_num,min_num;for(i=0;i<N;i++){for(j=0;j<N;j++){scanf("%d",&a[i][j]);}}max_num=a[0][0];min_num=a[0][0];for(i=0;i<N;i++){for(j=0;j<N;j++){if(max_num<a[i][j])max_num=a[i][j];if(min_num>a[i][j])min_num=a[i][j];}}二進制數(shù)據(jù)轉(zhuǎn)換成十進制數(shù)#include<stdio.h>#include<string.h>intmain(){chara[17];gets(a);intlen,i,sum=0,m,j;len=strlen(a);if(len<=16){for(i=0;i<len;i++){m=1;if(a[i]=='1'){for(j=1;j<=len-i-1;j++)m*=2;sum+=m;}}printf("%d",sum);}return0;}輸出整數(shù)各位數(shù)字#include<stdio.h>>stdlib.h#include<intmain(){100100];chara[longi;gets(a);\';a[i]!=;i++){(i=for0printf("%c",a[i]);}return0;}冒泡法排序#include<stdio.h>>stdlib.h#include<intmain(){];100a[intinti,j;intn,k;intt;"%d%d",&n,&k);scanf(for(i=0;i<n;i++)scanf("%d",&a[i]);;i<k;i++)0for(i=for(j=0;j<n-i-1;j++)if(a[j]>a[j+1]){t=a[j];a[j]=a[j+1];]=t;a[j+1}for(i=0;i<n-1;i++)printf("%d",a[i]);,a[i]);printf("%d"0;return}intx;doubleprice;printf("[1]apple\n"););"[2]pear\n"printf(printf("[3]orange\n");printf("[4]grape\n");"[0]exit\n");printf(for(i=0;i<5;i++){,&x);scanf("%d"switch(x){case0:end;goto:1caseprice=3;break;case2:price=2.5;break;:3caseprice=4.1;break;:4caseprice=10.2;break;default:0price=;評委打分#include<stdio.h>>stdlib.h#include<intmain(){inta[10];inti,j;intx;;i++)10;i<for(i=0,&a[i]);scanf("%d",&x);scanf("%d"for(j=0;j<x;j++){scanf("%d",&i);;10a[i-1]+=}9;i++);i<0(i=forprintf("%d",a[i]);printf("%d",a[9]);return0;}組合數(shù)的和#include<stdio.h>#include<stdlib.h>main()int{intns;inti,j;inta[10];intret,sum=0;"%d",&ns);scanf(for(i=0;i<ns;i++)scanf("%d",&a[i]);;i<ns;i++)0for(i=for(j=0;j<ns;j++){(a[i]!=a[j]){ifret=a[i]*10+a[j];sum+=ret;}}printf("%d",sum);return0;}scanf("%d",&n);0k=;for(i=0;i<n;i++){scanf("%d",&N);for(j=0;j<N;j++,k++),&b[k]);"%d"scanf(ns+=N;}for(i=0;i<ns;i++){if(b[i]==0)continue;cnt=1;for(j=i+1;j<ns;j++){if(b[i]==b[j]){cnt++;b[j]=0;}}(cnt>max_cnt||(cnt==max_cnt&&b[i]>max)){ifmax_cnt=cnt;max=b[i];}}printf("%d%d",max,max_cnt);return0;特別關(guān)注念數(shù)字#include<stdio.h>#include<stdlib.h>main(){intchara[100];},"san""er""yi"},{"ling"5][10b[char]={{"liu"{"si"},{"wu""qi""ba"},{"jiu"}};i;int,a);scanf("%s"for(i=0;a[i]!=;i++){){'-'if(a[i]==printf("fu");continue;}){0]==(a[i+if1printf("%s",b[a[i]-'0']);break;}printf("%s",b[a[i]-'0']);}0return;}數(shù)字加密#include<stdio.h>#include<stdlib.h>main(){intchara[5];inti;scanf("%s",a);;i++){;i<4(i=0for;)%910'0'a[i]=(a[i]-+}printf("Theencryptednumberis0]);13%c%c%c%c"2,a[],a[return0;}{intns;inti,j,k;intn;];][10a[intintflag;scanf("%d",&ns);;k<ns;k++){0for(k=flag=1;scanf("%d",&n);for(i=0;i<n;i++);j<n;j++)for(j=0,&a[i][j]);"%d"scanf(for(i=0;i<n;i++)0;j<i;j++)for(j=if(a[i][j]!=0){flag=0;break;}if(flag==1)printf("YES\n");elseprintf("NO\n");};return0}求矩陣各行元素之和#include<stdio.h>#include<stdlib.h>>#include<string.hintmain(){];],sum[][a[int6intm,n;inti,j;,&m,&n);scanf("%d%d";j<m;j++)0(j=forfor(i=0;i<n;i++)"%d",&a[j][i]);scanf(for(j=0;j<m;j++){sum[j]=0;;i<n;i++){0(i=forsum[j]+=a[j][i];}}for(i=0;i<m;i++){printf("%d",sum[i]);printf("\n");}0return;方陣循環(huán)右移#include<stdio.h>#include<stdlib.h>>#include<string.hintmain(){];],b[][a[int6intm,n;inti,j;,&m,&n);scanf("%d%d"0;j<n;j++)for(j=for(i=0;i<n;i++)scanf("%d",&a[j][i]);;j<n;j++){0(j=forfor(i=0;i<n;i++){b[j][(i+m)%n]=a[j][i];}};j<n;j++)0for(j=for(i=0;i<n;i++){printf("%d",b[j][i]);if((i+1)%n==0)"\n");printf(}統(tǒng)計字符出現(xiàn)次數(shù)#include<stdio.h>>stdlib.h#include<intmain(){charstring[80];charch;*str;charinti=0;gets(string);ch=getchar();;str++){for(str=string;*str!='\0(*str==ch)ifi++;}printf("%d",i);return0;}統(tǒng)計大寫輔音字母#include<stdio.h>#include<stdlib.h>main()int{inti;intns=0;charstring[81];gets(string);;i++){;string[i]!=0(i=forif(string[i]>='A'&&string[i]<='Z'&&string[i]!='A''E''O'&&string[i]!='I'&&string[i]!='U')ns++;},ns);"%d"printf(return0;}字符串字母大小寫轉(zhuǎn)換#include<stdio.h>>stdlib.h#include<#include<string.h>main()int{charstring[30];charc;inti;;i=0c=getchar();'#'while(c!=){'z')&&c<=if(c>='a'c-=('a'-'A');elseif(c>='A'&&c<='Z')'A');-c+=('a'string[i]=c;i++;c=getchar();}0;string[i]=printf("%s",string);;return0}#include<string.h>intmain(){charstring[5][80];5];char*str[inti,j;char*t;;i++){5;i<(i=for0scanf("%s",string[i]);str[i]=string[i];};i++){4;i<0(i=for4;j<;j++){(j=for0if(strcmp(str[j],str[j+1])>0){t=str[j];];1str[j]=str[j+str[j+1]=t;}}});"Aftersorted:\n"printf(for(i=0;i<5;i++){"%s\n",str[i]);printf(}找兩個數(shù)中最大者intmax(a,b){returna>b?a:b;}簡單實現(xiàn)x的n次方n){x,intdoublemypow(doubleret=1.0;ret=pow(x,n);ret;return}彈球距離doubledist(h,p){doublev;doubles;s=h;v=h*p;while(v>=TOL){s+=2*v;v=v*p;}returns;}使用函數(shù)求最大公約數(shù)intgcd(x,y){intt;t=(x<y?x:y);y=x+y-t;x=t;while(x!=0){t=x;x=y%x;y=t;}returny;}使用函數(shù)輸出一個整數(shù)的逆序數(shù)intreverse(number){intret=0;,v;1i=intv=number;while(fabs(v)>9){v/=10;i++;}while(i>=0){1,i-);10ret+=(number%)*pow(number/=10;i--;}returnret;}使用函數(shù)求奇數(shù)和inteven(n){if(n%2!=0);0returnelsereturn1;}N){List[],OddSum(intintsum=0;inti;0;i<N;i++){for(i=if(even(List[i])==0)sum+=List[i];}returnsum;}使用函數(shù)求特殊a串數(shù)列和intfn(a,n){;0intret=inti;for(i=0;i<n;i++){10ret+=a*pow(,i);}returnret;}intSumA(a,n){inti;;0sum=intfor(i=1;i<=n;i++){sum+=fn(a,i);}returnsum;}使用函數(shù)求素數(shù)和intprime(p){inti;if(fabs(p)<2)0;returnfor(i=2;i<=sqrt(p);i++)if(p%i==0)break;if(i>sqrt(p));1returnreturn0;}intPrimeSum(m,n){0;intsum=intp;for(p=m;p<=n;p++){if(prime(p)!=0)sum+=p;}sum;return}統(tǒng)計各位數(shù)字之和是5的數(shù)intis(number){intsum=0;while(number!=0){;sum+=number%10number/=10;}if(sum==5)return1;;0return}voidcount_sum(inta,b){inti;;intcnt=0;0s=intfor(i=a;i<=b;i++)if(is(i)){cnt++;s+=i;}"count=%d,sum=%d",cnt,s);printf(}簡單求和intSum(List[],N){inti;;0sum=intfor(i=0;i<N;i++)sum+=List[i];returnsum;}多項式求值//doublepower(doublex,inti);doublef(intn,a[],x){;0.0ret=doubledoublep=1.0;inti;for(i=0;i<=n;i++){ret+=(a[i]*p);p*=x;}returnret;}//智障題目/*doublepower(doublex,inti){doublep=1.0;intj;for(j=0;j<i;j++)p*=x;returnp;}*/移動字母/*voidGetString(char*s){charch;inti=0;while(

溫馨提示

  • 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

提交評論