版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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;}四則運(yùn)算(switch語(yǔ)句)#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個(gè)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;}計(jì)算學(xué)生成績(jī)平均分,輸出高于平均分的成績(jī)#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、輸入一串字符刪除其中一個(gè)#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';}計(jì)算個(gè)人所得稅#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、定義一個(gè)中國(guó)省份基本信息結(jié)構(gòu),包括省名、簡(jiǎn)稱(chēng)、面積(萬(wàn)平方公里)、人口(萬(wàn)人)等。編寫(xiě)程序,輸入五個(gè)省份的信息,輸出其中面積最大的省份是哪一個(gè)?(使用結(jié)構(gòu)體實(shí)現(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矩陣,第一個(gè)左乘第二個(gè)#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;}韓信點(diǎn)兵,最少人數(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;}輸入一字符串,求英文字符個(gè)數(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)類(lèi)型來(lái)表示二維平面坐標(biāo)中一點(diǎn),求兩點(diǎn)連線中點(diǎn)坐標(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ù)組中所有元素移動(dòng)m個(gè)位置溫度轉(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;}大寫(xiě)字母轉(zhuǎn)換小寫(xiě)#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;}輸入一個(gè)正整數(shù)n,再輸入0~9中的任意一個(gè)數(shù)x,統(tǒng)計(jì)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)計(jì)字符個(gè)數(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;}}求字符串長(zhǎng)度#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個(gè)點(diǎn),判斷并輸出哪個(gè)點(diǎn)距離坐標(biāo)原點(diǎn)最遠(yuǎn)#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;}百分制的成績(jī)轉(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ā)書(shū)包#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;}}出租車(chē)#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;}輸入一字符,小寫(xiě)轉(zhuǎn)換大寫(xiě)#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)個(gè)學(xué)生的成績(jī)等級(jí)(A、B、C、D、E五個(gè)等級(jí)),編寫(xiě)函數(shù)intCount_number(char*m,intn,chargrade),統(tǒng)計(jì)指定成績(jī)等級(jí)#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ù)中輸入一個(gè)字符,再輸入一個(gè)以回車(chē)結(jié)束的字符串(少于80個(gè)字符),調(diào)用函數(shù)search()查找該字符在字符串中所對(duì)應(yīng)的最大下標(biāo)(下標(biāo)從0開(kāi)始);若沒(méi)找到則輸出“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;}計(jì)算出租車(chē)費(fèi)用(某城市很奇怪,打出租車(chē)15公里(包括)以下,按每公里2元計(jì)費(fèi),而大于15公里卻按照每公里3元計(jì)費(fèi)),小明想編寫(xiě)一個(gè)程序,其功能為:在主函數(shù)中輸入打車(chē)公里數(shù),用戶自定義函數(shù)將求出應(yīng)付給司機(jī)的租車(chē)費(fèi)用,并返回給主函數(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;}從鍵盤(pán)輸入6個(gè)整數(shù)存到數(shù)組中,輸出其最大值和它所對(duì)應(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次落地時(shí),共經(jīng)過(guò)多少米?第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點(diǎn),判斷并輸出哪個(gè)點(diǎn)距離(-1,3)最遠(yuǎn)#include<stdio.h>structpoint{doublex1,x2;doubley1,y2;};intmain(){struct
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025飯店轉(zhuǎn)包合同范文
- 2025年度養(yǎng)老機(jī)構(gòu)寵物養(yǎng)護(hù)服務(wù)合同示范文本3篇
- 二零二五年度競(jìng)業(yè)禁止勞動(dòng)合同在文化產(chǎn)業(yè)的關(guān)鍵作用3篇
- 二零二五年度公租房合同簽訂及補(bǔ)貼發(fā)放協(xié)議3篇
- 二零二五年度學(xué)校食堂兼職校醫(yī)食品安全合同2篇
- 二零二五年度素食餐飲技術(shù)加盟經(jīng)營(yíng)合同2篇
- 二零二五年度土方運(yùn)輸車(chē)輛智能化改造與升級(jí)合同3篇
- 二零二五年度新能源電動(dòng)汽車(chē)租賃合同2篇
- 2025年度年度租賃車(chē)輛保險(xiǎn)責(zé)任協(xié)議3篇
- 2025年度極限運(yùn)動(dòng)賽事委托承辦授權(quán)協(xié)議3篇
- IDC云數(shù)據(jù)中心機(jī)房運(yùn)維服務(wù)解決方案
- 產(chǎn)品經(jīng)理必備BP模板(中文版)
- 維西縣城市生活垃圾熱解處理工程環(huán)評(píng)報(bào)告
- GB/T 9128.2-2023鋼制管法蘭用金屬環(huán)墊第2部分:Class系列
- 網(wǎng)絡(luò)經(jīng)濟(jì)學(xué)PPT完整全套教學(xué)課件
- 2023年主治醫(yī)師(中級(jí))-臨床醫(yī)學(xué)檢驗(yàn)學(xué)(中級(jí))代碼:352考試參考題庫(kù)附帶答案
- 機(jī)械原理課程設(shè)計(jì)鎖梁自動(dòng)成型機(jī)床切削機(jī)構(gòu)
- 順產(chǎn)臨床路徑
- 人教版培智一年級(jí)上生活適應(yīng)教案
- 推動(dòng)架機(jī)械加工工序卡片
- RoHS檢測(cè)報(bào)告完整版
評(píng)論
0/150
提交評(píng)論