c語言知識考試題庫_第1頁
c語言知識考試題庫_第2頁
c語言知識考試題庫_第3頁
c語言知識考試題庫_第4頁
c語言知識考試題庫_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、是否構(gòu)成三角形#include<stdio.h>intmain(void){inta,b,c;scanf("%d%d%d",&a,&b,&c);if((a+b>c)&&(b+c>a)&&(a+c>b)){printf("Yes");}else{printf("No");}return0;}四則運算(switch語句)#include<stdio.h>intmain(void){intnum1,num2,result;charop;scanf("%d%c%d",&num1,&op,&num2);switch(op){case'+':result=num1+num2;break;case'-':result=num1-num2;break;case'*':result=num1*num2;break;case'/':result=num1/num2;break;default:printf("inputfail\n");break;}printf("%d\n",result);return0;}正整數(shù)幾位(count)#include<stdio.h>intcount(intn);intmain(void){intx,w;printf("Enteranumber:");scanf("%d",&x);w=count(x);printf("%d",w);return0;}intcount(intn){intcount=1;while(n/10!=0){n=n/10;count++;}returncount;}Sn=a+aa+aaa......(n個a)#include<stdio.h>intmain(){intn,a,i,t;intsum;sum=0;scanf("%d%d",&n,&a);t=a;for(i=1;i<=n;i++){sum=sum+t;t=t*10+a;}printf("%d\n",sum);return0;}雞兔同籠(35頭,49腳)#include<stdio.h>intmain(){intchi,rab;for(chi=1;chi<=35;chi++){for(rab=1;rab<=25;rab++){if(chi+rab==35&&2*chi+4*rab==94){printf("thechikenhave:%d\ntherabbithave:%d",chi,rab);}}}return0;}計算學(xué)生成績平均分,輸出高于平均分的成績#include<stdio.h>intmain(void){inti;intsum=0;inta[6];floataverage;for(i=0;i<6;i++){scanf("%d",&a[i]);sum+=a[i];}average=sum/6.0;printf("%0.2f\n",average);for(i=0;i<6;i++){if(a[i]>average)printf("%d\n",a[i]);}return0;7、三角形面積(main和自定義函數(shù))#include<stdio.h>#include<math.h>intaera(inta,intb,intc);intmain(){inta,b,c;scanf("%d%d%d",&a,&b,&c);printf("%d",aera(a,b,c));return0;}intaera(inta,intb,intc){ints,l;l=(a+b+c)/2;s=sqrt(l*(l-a)*(l-b)*(l-c));returns;}8、1、1\4、1\7.......1\n之和#include<stdio.h>intmain(void){inti,n;floatsum=0;intnum=1;scanf("%d",&n);for(i=1;i<=n;i++){sum+=1.0/num;num+=3;}printf("%0.2f",sum);return0;}9、輸入一串字符刪除其中一個#include<stdio.h>voiddelchar(char*s,charc);intmain(){chars[100];charc;printf("Enterastring:");gets(s);printf("Enterac:");scanf("%c",&c);delchar(s,c);printf("%s\n",s);return0;}voiddelchar(char*s,charc){char*p;for(p=s;*s;s++)if(*s!=c)*p++=*s;*p='\0';}計算個人所得稅#include<stdio.h>doublewage(doublex);intmain(){doublen,a;printf("enterwage:");scanf("%lf",&n);a=wage(n);printf("therealwageis:%.2f\n",a);return0;}doublewage(doublex){doubletax,wages;if(x>=7000){tax=x*0.1;wages=x-tax;}elseif(x<7000){tax=x*0.05;wages=x-tax;}returnwages;}11、定義一個中國省份基本信息結(jié)構(gòu),包括省名、簡稱、面積(萬平方公里)、人口(萬人)等。編寫程序,輸入五個省份的信息,輸出其中面積最大的省份是哪一個?(使用結(jié)構(gòu)體實現(xiàn))#include<stdio.h>structchina{charname[20];charabb[20];intarea;intpopu;};intmain(){inti,j,temp;structchinainfor[5];for(i=0;i<5;i++){printf("enterthe%dprovincesname:",i+1);scanf("%s",&infor[i].name);printf("enterthe%dprovincesabb:",i+1);scanf("%s",&infor[i].abb);printf("enterthe%dprovincesarea:",i+1);scanf("%d",&infor[i].area);printf("enterthe%dprovincespopu:",i+1);scanf("%d",&infor[i].popu);}for(j=0;i<5;j++){if(infor[j].area>infor[j+1].area){temp=infor[j].area;infor[j].area=infor[j+1].area;infor[j+1].area=temp;}}printf("themaximumsizeoftheprovicesis:%s",infor[4].name);return0;}n*n矩陣,第一個左乘第二個#include<stdio.h>#include<string.h>intmain(){intn;inti,j,l;intlove=0,maxlove=0;while(printf("EnteraInteger:n(0<=n<=20):\n")!=EOF&&scanf("%d",&n)!=EOF){intx[n][n];inty[n][n];for(i=0;i<n;i++){for(j=0;j<n;j++){scanf("%d",&x[i][j]);}}for(i=0;i<n;i++){for(j=0;j<n;j++){scanf("%d",&y[i][j]);}}for(l=0;l<n;l++){for(i=0;i<n;i++){for(j=0;j<n;j++){love+=x[l][j]*y[j][i];}if(love>maxlove){maxlove=love;}love=0;}}printf("%d\n",maxlove);}return0;}韓信點兵,最少人數(shù)(枚舉法)#include<stdio.h>intmain(void){intsum=0;while(1!=sum%5||5!=sum%6||4!=sum%7||10!=sum%11){sum++;}printf("%d\n",sum);return0;}14、兩數(shù)立方和(自定義函數(shù))#include<stdio.h>intsum_(intx,inty);intmain(){intnum1,num2,sums;printf("entertwointegers:");scanf("%d%d",&num1,&num2);sums=sum_(num1,num2);printf("%d\n",sums);return0;}intsum_(intx,inty){intsum;sum=x*x*x+y*y*y;returnsum;}三數(shù)平均值(自定義函數(shù))#include<stdio.h>floataver(floatnum1,floatnum2,floatnum3);intmain(void){floatnum1,num2,num3;doubleaverage;scanf("%f%f%f",&num1,&num2,&num3);average=aver(num1,num2,num3);printf("aversge=%.2f",average);return0;}floataver(floatnum1,floatnum2,floatnum3){return(num1+num2+num3)/3.0;}輸入一字符串,求英文字符個數(shù)并輸出#include<stdio.h>intmain(){intcount,i;charstr[80];i=0;while((str[i]=getchar())!='\n')i++;str[i]='\0';count=0;for(i=0;str[i]!='\0';i++){if(((str[i]<='Z')&&(str[i]>='A'))||((str[i]>='a')&&(str[i]<='z')))count++;}printf("%d",count);return0;}定義結(jié)構(gòu)類型來表示二維平面坐標(biāo)中一點,求兩點連線中點坐標(biāo)#include<stdio.h>structpoint{floatx;floaty;};intmain(void){structpointtemp1;structpointtemp2;scanf("%f%f",&temp1.x,&temp1.y);scanf("%f%f",&temp2.x,&temp2.y);printf("%0.2f%0.2f",(temp1.x+temp2.x)/2.0,(temp1.y+temp2.y)/2.0);return0;}movn元素的數(shù)組中所有元素移動m個位置溫度轉(zhuǎn)換#include<stdio.h>doublecelsius(intf);intmain(){doublec,f;while(scanf("%lf",&f)!=EOF){c=celsius(f);printf("%.2f\n",c);}return0;}doublecelsius(intf){return5*(f-32)/9.0;}大寫字母轉(zhuǎn)換小寫#include<stdio.h>#include<string.h>intmain(void){inti;chararray[100];gets(array);for(i=0;array[i]!='\0';i++){if('A'<=array[i]<='Z')array[i]=array[i]-'A'+'a';}puts(array);return0;}閏年#include<stdio.h>intmain(void){intyear;scanf("%d",&year);if(year%4==0&&year%100!=0||year%400==0){printf("YES\n");}else{printf("NO\n");}return0;}輸入一個正整數(shù)n,再輸入0~9中的任意一個數(shù)x,統(tǒng)計x在n中出現(xiàn)的次數(shù)#include<stdio.h>intmain(void){intn,x,i;scanf("%d%d",&n,&x);intcount=0,t;t=n;for(i=1;i<=n;i++){t=n%10;n=n/10;if(t==x){count++;}if(n==0&&t==0){break;}}printf("%d\n",count);return0;}猴子吃桃#include<stdio.h>intmain(){inti;inttao=1;for(i=1;i<10;i++){tao=2*(tao+1);}printf("%d\n",tao);return0;}統(tǒng)計字符個數(shù)#include<stdio.h>intmain(){chars[]="2ds34fjd58w6d";intcount,i;count=0;for(i=0;s[i]!='\0';i++){count++;}printf("%d\n",count);return0;}25、兩整數(shù)之間的偶數(shù)的和#include<stdio.h>intsum(inta,intb);intmain(){inta,b;scanf("%d%d",&a,&b);printf("%d\n",sum(a,b));return0;}intsum(inta,intb){inti;intsum=0;for(i=a;i<=b;i++){if(i%2==0){sum+=i;}}returnsum;}m,n之間水仙花數(shù)m≥100,n≤1000#include<stdio.h>intisNarciss(intn);intmain(void){intm,n,i;scanf("%d%d",&m,&n);for(i=m;i<=n;i++){if(isNarciss(i)){printf("%d\n",i);}}return0;}intisNarciss(intn){inta,b,c;a=n/100;b=n/10%10;c=n%10;if(a*a*a+b*b*b+c*c*c==n){return1;}else{return0;}}求字符串長度#include<stdio.h>#include<string.h>#defineMAX2000intmain(void){charstr[MAX];gets(str);inti;for(i=0;;i++){if(str[i]=='\0'){printf("%d",i+1);break;}}return0;}28、輸入2個點,判斷并輸出哪個點距離坐標(biāo)原點最遠#include<stdio.h>#include<math.h>typedefstructpointer{floatx;floaty;}pot;intmain(void){pota,b;scanf("%f%f%f%f",&a.x,&a.y,&b.x,&b.y);if(a.x*a.x+a.y*a.y>b.x*b.x+b.y*b.y){printf("%.2f%.2f\n",a.x,a.y);}if(a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y){printf("%.2f%.2f\n",b.x,b.y);}else{printf("%.2f%.2f/%.2f%.2f\n",a.x,a.y,b.x,b.y);}return0;}百分制的成績轉(zhuǎn)換為A或者B#include<stdio.h>#include<string.h>charchange(intn);intmain(void){intn;scanf("%d",&n);printf("%c\n",change(n));return0;}charchange(intn){if(n>=60){return'A';}else{return'B';}}批發(fā)書包#include<stdio.h>intcount(intn);intmain(void){intn;scanf("%d",&n);printf("%d\n",count(n));return0;}intcount(intn){if(n<60){return60*n;}else{return45*n;}}出租車#include<stdio.h>intmain(void){intn;floaty;scanf("%d",&n);if(n<=3){y=10;}else{y=10+(n-3)*1.5;}printf("%.2f",y);return0;}輸入一字符,小寫轉(zhuǎn)換大寫#include<stdio.h>intmain(void){chars;scanf("%c",&s);if(s>=97){s=s-32;}printf("%c\n",s);return0;}字符數(shù)組Marks保存有n(n<20)個學(xué)生的成績等級(A、B、C、D、E五個等級),編寫函數(shù)intCount_number(char*m,intn,chargrade),統(tǒng)計指定成績等級#include<stdio.h>intmain(void){intcount_number(char*m,intn,chargrade);inta,i,number;scanf("%d",&a);charMark[a];for(i=0;i<a;i++)scanf("%c",Mark[i]);number=count_number(Mark,a,'B');printf("%d",number);return0;}intcount_number(char*m,intn,chargrade){intz=0,i;for(i=0;i<n;i++){if(grade==*(m+i))z=z+1;}}34、在主函數(shù)中輸入一個字符,再輸入一個以回車結(jié)束的字符串(少于80個字符),調(diào)用函數(shù)search()查找該字符在字符串中所對應(yīng)的最大下標(biāo)(下標(biāo)從0開始);若沒找到則輸出“NotFound!”。函數(shù)原型:intsearch(char*s,charx)。#include<stdio.h>intmain(void){intsearch(char*s,charx);inta;charc;charstring[80];scanf("%c%s",&c,string);a=search(string,c);if(a==-1)printf("NoFound");elseprintf("%d",a);return0;}intsearch(char*s,charx){inti,z,c;intcount=0;for(i=0;i<80;i++){if(x==*(s+i)){count=count+1;c=i;}}if(count!=0)z=c;elsez=-1;returnz;}計算出租車費用(某城市很奇怪,打出租車15公里(包括)以下,按每公里2元計費,而大于15公里卻按照每公里3元計費),小明想編寫一個程序,其功能為:在主函數(shù)中輸入打車公里數(shù),用戶自定義函數(shù)將求出應(yīng)付給司機的租車費用,并返回給主函數(shù)。#include<stdio.h>intmain(void){floatcost(floatklio);floatkli;floatc;scanf("%f",&kli);c=cost(kli);printf("%f",c);return0;}floatcost(floatklio){floatz;if(klio<=15)z=2*klio;elsez=3*klio;returnz;}從鍵盤輸入6個整數(shù)存到數(shù)組中,輸出其最大值和它所對應(yīng)的的下標(biāo)#include<stdio.h>intmain(){inta[6];inti;intmax=0;for(i=0;i<6;i++){scanf("%d",&a[i]);}for(i=1;i<6;i++)if(a[max]<a[i])max=i;printf("%d%d",a[max],max);return0;}球100米落下、第10次落地時,共經(jīng)過多少米?第10次反彈多高?#include<stdio.h>intmain(){inti;doubleh=100,temp=100;doubles;for(i=1;i<=10;i++){h=h/2;s=s+temp;temp=2*h;}printf("%.2f%.2f\n",h,s);return0;}38、輸入2點,判斷并輸出哪個點距離(-1,3)最遠#include<stdio.h>structpoint{doublex1,x2;doubley1,y2;};intmain(){struct

溫馨提示

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

評論

0/150

提交評論