版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、第五章5.1#include<stdio.h>voidmain()(doublex;printf(“請輸入一個(gè)實(shí)數(shù):n");scanf(H%lf",&x);if(x>0)(printf("%fn”,x);)else(printf(,%fnK,-x);)5.2#inelude<stdio.h>main()(inta,b;printf(“請輸入一個(gè)整數(shù):");scanf("%d",&a);b=a%2;if(b=O)(printf(*'%d為偶數(shù)n'a);)else(printf
2、(*'%d為奇數(shù)n'a);)5.3#include<stdio.h>#include<math.h>main()(floata,b,c,s,area;printf("請輸入三邊長:”);scanf(n%f,%f,%f",&a,&b,&c);s=(a+b+c)/2;area=(float)sqrt(s*(s-a)*(s-b)*(s-c);if(a+b>c)&&(a+c>b)&&(b+c>a)(printf("這個(gè)三角形的面積為%fn'area);
3、)else(printf("這三條邊不能組成三角形n*');)5.4#include<stdio.h>#include<math.h>voidmain()(doublea,b,c5d,e,x1,x2;printf("請輸入a,b,c:");scanf("%lf,%lf,%ir,&a,&b,&c);if(a=0)(printf("該方程不是一元二次方程.n");)elseif(b*b-4*a*c>0)(d=sqrt(b*b-4*a*c);x仁(b+d)/(2*a);x2=(-
4、b-d)/(2*a);printf("x1=%f,x2=%fn",x1,x2);)elseif(b*b-4*a*c=0)x1=(-b)/(2*a);printf(Hx1=x2=%fnn,x1);)elseif(b*b-4*a*c<0)(printf("該方程沒有實(shí)數(shù)解.n“);)5.5#include<stdio.h>main()(intyear,flag;printf("輸入年份:“);scanf("%dH,&year);if(year%4=0)&&(year%100!=0)|(year%400=0)
5、flag=1;)else(flag=O;)if(flag=1)(printf("d是閏年n",year);)else(printf("d不是閏年nH,year);)6.6#include<stdio.h>voidmain()(intyear,flag;printf("輸入年份:“);scanf("%du,&year);flag=(year%4=0)&&(year%100!=0)|(year%400=0)?1:2;if(flag=1)(printf(”d年是閏年n",year);)else(print
6、f(*'%d年不是閏年n",year);)5.7#include<stdio.h>main()(charch;printf("請輸入一個(gè)字母:");ch=getchar();if(ch>=65)&&(ch<=90)(ch=ch+32;printf(-c,%dn”,ch,ch);)elseif(ch>=97)&&(ch<=122)ch=ch-32;printf(-c,%dn”,ch,ch);)elseprintf(n%cnn5ch);5.8#include<stdio.h>mai
7、n()(charch;printf(“請輸入一個(gè)字符:");ch=getchar();if(ch>=48)&&(ch<=57)(printf("這是一個(gè)數(shù)字字符.n");)elseif(ch>=65)&&(ch<=90)(printf("這是一個(gè)大寫字母.W);)elseif(ch>=97)&&(ch<=122)(printf("這是一個(gè)小寫字母.n“);)elseif(ch=32)(printf("這是一個(gè)空格字符.n“);)else(printf(
8、"這是一個(gè)其它字符.W);)5.9#include<stdio.h>main()intscore,mark;printf(HPleaseenterscore:1');scanf(八d”,&score);if(score<0|score>100)(printf("lnputerror!*n*');)elseif(score>=90&&score<=100)printf("d-An”,score);)elseif(score>=80&&score<90)(print
9、f(”%d-Bn”,score);)elseif(score>=70&&score<80)(printf(”%d-Cn”,score);)elseif(score>=60&&score<70)(printf(n%d-Dn",score);else(printf("%d-En”,score);)5.10#include<stdio.h>#include<stdlib.h>main()(intflag,year,month,day,day仁31,day2=30,day3=29,day4=28;pri
10、ntf("請以2012,03這種形式輸入某年某月:scanf("%d,%dH,&year,&month);if(month>12|month<1)printf("你輸入的年份不在合法范圍內(nèi)n");exit(O);)else(flag=(year%4=0&&year%1OO!=O|year%400=0)?1:0;switch(flag)(case1:prints閏年)break;case0:printf(“平年”);break;)if(month=2&&flag=1)day=day3;elseif
11、(month=2&&flag=O)day=day4;switch(month)(case1:case3:case5:case 7:case 8:case10:case12:printf("%d年,d月?lián)碛械奶鞌?shù)是31.nM,year,month);break;case4:case6:case9:case11:printf("%d年,d月?lián)碛械奶鞌?shù)是30.n",year,month);break;default:printf(M%d年,d月?lián)碛械奶鞌?shù)是%d:nM,year,month,day);本章實(shí)驗(yàn)題1#include<stdio.h>
12、;main()doublefaheight,maheight;charsex,sports,diet,F,M,Y,N;printf("請輸入父母的身高:n");scanf("%lf,%lf",&faheight,&maheight);printf("請輸入孩子是男孩還是女孩(F/M):n“);scanty%c",&sex);printf("請輸入孩子是否喜歡鍛煉身體(Y/N):n“);scanf(n%cH,&sports);printf("請輸入孩子是否有良好的飲食習(xí)慣(Y/N):n
13、");scanf(n%cH,&diet);if(sex=77&&sports=89&&diet=89)(printf(“該孩子成人時(shí)身高約為:%.2f.n",(faheight+maheight)*0.54*1.02*1.015);)elseif(sex=77&&sports=89&&diet=78)(printf("該孩子成人時(shí)身高約為:%.2f.nM,(faheight+maheight)*0.54*1.02);)elseif(sex=77&&sports=78&&
14、amp;diet=89)(printf(“該孩子成人時(shí)身高約為:%.2f.nM,(faheight+maheight)*0.54*1.015);)elseif(sex=77&&sports=78&&diet=78)printf("該孩子成人時(shí)身高約為:%.2f.nn,(faheight+maheight)*0.54);elseif(sex=70&&sports=89&&diet=89)printf("該孩子成人時(shí)身高約為:%.2f.nH,(faheight*0.923+maheight)/2*1.02*1.01
15、5);elseif(sex=70&&sports=89&&diet=78)printf("該孩子成人時(shí)身高約為:%.2f.nH,(faheight*0.923+maheight)/2*1.02);)elseif(sex=70&&sports=78&&diet=89)(printf(“該孩子成人時(shí)身高約為:%.2f.nH,(faheight*0.923+maheight)/2*1.015);)elseif(sex=70&&sports=78&&diet=78)(printf("該孩
16、子成人時(shí)身高約為:%.2f.n",(faheight*0.923+maheight)/2);)本章實(shí)驗(yàn)題2#include<stdio.h>main()(doublet,w,h;printf(”請輸入體重身高:n”);scanf("%lf,%lf",&w,&h);t=w/(h*h);if(t<18)(printf("低體重.H);)if(t>=18&&t<25)(printf("正常體重.n");)if(t>=25&&t<27)printf(&q
17、uot;超重體重.n");if(t>=27)printf(M肥胖.n”);)弟八早6.1 #include<stdio.h>main()(intij,k;charspace-';for(i=1;iv=4;i+)(for(j=1;jv=i;j+)(printf("%c",space);)for(k=1;k<=6;k+)(prinprintfC'n");)6.1(2)#include<stdio.h>main()(intk=4,n;for(n=0;n<k;n+)(if(n%2=0)continue;k
18、-;)printf("k=%dn,n=%dnu,k,n);6.1(3)#include<stdio.h>main()(intk=4,n;for(n=0;n<k;n+)(if(n%2=0)break;k-;)printf("k=%d,n=%dnH,k,n);)6.2(1)# include<stdio.h>main()(inti,sum=0;for(i=1;i<=101;i=i+2)(sum=sum+i;)printf("sum=%dnn,sum);)6.2(2)# include<stdio.h>main()(lon
19、gi;longterm,sum=0;for(i=1;i<=99;i=i+2)term=i*(i+1)*(i+2);sum=sum+term;)printf(nsum=%ldn",sum);)6.2(3)# include<stdio.h>main()(longterm=0,sum=0;inta,i,n;printf("lnputa,n:n);scanf("%d,%d",&a,&n);for(i=1;i<=n;i+)(term=term*10+a;sum=sum+term;)printf(nsum=%ldnH,sum
20、);)6.2(4)#include<stdio.h>#include<math.h>main()(intn=1;floatterm=1.0,sign=1,sum=0;while(fabs(term)>=1e-4)(term=sign/n;sum=sum+term;sign=-sign;n+;)printf("sum=%fnu);)6.2(5)#include<stdio.h>#include<math.h>main()(intn=15count=1;floatx;doublesum,term;printf('1nputx:
21、u);scan&x);sum=x;term=x;doterm=-term*x*x/(n+1)*(n+2);sum=sum+term;n=n+2;count+;Jwhile(fabs(term)>=1e-5);printf("sin(x)=%f,coumt=%dn",sum,count);)6.3#include<stdio.h>main()(intx=1,find=0;while(!find)(if(x%2=1&&x%3=2&&x%5=4&&x%6=5&&x%7=0)(find=1;)
22、x+;)printf("x=%dnn,x-1);)6.4#include<stdio.h>main()(inti,n;longpj;printf("Pleaseentern:");scanf(n%d",&n);for(i=1;i<=n;i+)(P=i*i;j=i*i*i;printf("%d*%d=%ldn",i,i,p);printf(H%d*%d*%d=%ldn,',i,i,i,j);6.5#include<stdio.h>main()(doubleC,F,i;for(F=-40;F&
23、lt;=110;F=F+10)C=%fn"EC);C=(F-32)*5/9;printf(T=%f)6.6#include<stdio.h>main()(doublep=1+0.01875*12,x4,x3,x2,benjin;x4=1000/p;x3=(x4+1000)/p;x2=(x3+1000)/p;benjin=(x2+1000)/p;printf("本金為:%f",benjin);)6.7#include<stdio.h>main()(doublecount=0,c,d5sum=100;printf('1nputcscan
24、f("%lf",&c);d=c/100.0;dosum=sum*(1+d);count+;while(sum<=200);printf("count=%fnn,count);6.8#include<stdio.h>#include<math.h>main()(intcount=1;doublesum=1.0,term,n=3.0J=1.0;doterm=-i/n;sum=sum+term;n=n+2;I=-I;count+;while(fabs(term)>=1e-5);printf(Hn=%lf,count=%d.n&
25、quot;,4*sum,count);6.9# include<stdio.h># inelude<math.h>main()(intcount=1;doublesum=1.0,term=1.0,n=1.0;while(fabs(term)>=1e-5)(term=term/n;sum=sum+term;n+;count+;)printf(He=%lf,count=%d.nfl,sum5count);)6.10# include<stdio.h>main()(inti,a,b,c5d;for(i=100;i<=999;i+)(a=i/100;c=
26、i%10;b=(i-a*100-c)/10;d=a*a*a+b*b*b+c*c*c;if(i=d)(printf('1=%dn",i);)6.11#include<stdio.h>main()longm=2,n,term=1,sum=1;printf(Hlnputn:H);scanf("%ld",&n);doterm=term*m;sum=sum+term;m+;while(sum<=n);printf("m=%d.n”,m-2);)6.12#include<stdio.h>main()(intnum=1,s
27、um=0,count=0;while(num>0)(printf('1nputnum:");scanf(n%d",&num);sum=sum+num;count+;)printf("sum=%d,count=%d.nH,sum,count-1);6.13# include<stdio.h>main()(intterm,sum=0,count=0;dobegin:printf('1nputterm:");scant(n%d",&term);if(term>0)(sum=sum+term;co
28、unt+;)elseif(term<0)gotobegin;elsegotoend;Jwhile(term!=0);end:printf(Hsum=%d.count=%d.nlsum,count);)6.14# include<stdio.h>main()(inta,b,c;for(a=0;a<17;a+)for(b=0;b<=25;b+)(c=30-a-b;if(a*3+b*2+c=50)printf("男=%"女=%"孩子=%d.n",a,b,c);)6.15# include<stdio.h>main()(
29、inta,b;for(a=0;a<=98;a+)b=98-a;67孑蠱丹*ncludAsfdp-hv6-8ma-n()一三XXNfor(XH一八Xfor(yHy二(XAIo八X+A20八y+10+y5+zHuI00)-f(apz.nff*4Hu386)n由血QdJn云-66*ncludAsfd-O.hvmain。-一NFXMNfor(XHoXAH2oX+)-for(yHol<AH33P+)-zJoo-x-y八二(5*x+3*y+z、30HH-oo一-Dz.nff(=XH%dlyH%dN上:#include<stdio.h>main()(inti,j;for(i=1;i&
30、lt;=9;i+)(for(j=1;jv=9;j+)(printf(',%-5d',i*j);)printf("n");)左:#include<stdio.h>main()(inti,j;for(i=1;i<=9;i+)(for(j=1;j<=i;j+)(printf(',%-5d',i*j);)printf("n");)右:#include<stdio.h>main()(inti,j,a=1,k;charb='*;for(i=1;i<=9;i+)for(k=1;k<
31、=i;k+)for(j=i;j<=9;j+)(a=j*i;printf(n%5d",a);)printf("n");)6.19#include<stdio.h>main()(longi,summo;doublesumfu=0,term=0.01;summo=100000*30;for(i=1;i<=30;i+)(term=term*2.0;sumfu=sumfu+term;)printf("陌生人付ld,富翁付%lf.nH,summo,sumfu);)本章實(shí)驗(yàn)題2.1#include<stdio.h>#include<stdlib.h>#include<time.h>main()(intx1,x2,c,answer;begin:s
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025版宿舍樓智能監(jiān)控設(shè)施承包合同3篇
- 2025年度木材貿(mào)易與木工加工合作合同4篇
- 夏令營2025非傳統(tǒng)教育項(xiàng)目合作合同3篇
- 2025年度木材加工廠設(shè)備租賃合同范本7篇
- 《漢服唯美古詩句》課件
- 2025版實(shí)習(xí)員工實(shí)習(xí)期間住宿安排合同3篇
- 養(yǎng)生保健與中醫(yī)養(yǎng)生藥物考核試卷
- 合成革表面處理與涂飾技術(shù)考核試卷
- 2025版智能電網(wǎng)信息安全防護(hù)合同4篇
- 創(chuàng)業(yè)空間科技創(chuàng)新平臺考核試卷
- 《天潤乳業(yè)營運(yùn)能力及風(fēng)險(xiǎn)管理問題及完善對策(7900字論文)》
- 醫(yī)院醫(yī)學(xué)倫理委員會章程
- xx單位政務(wù)云商用密碼應(yīng)用方案V2.0
- 農(nóng)民專業(yè)合作社財(cái)務(wù)報(bào)表(三張報(bào)表)
- 動土作業(yè)專項(xiàng)安全培訓(xùn)考試試題(帶答案)
- 大學(xué)生就業(yè)指導(dǎo)(高職就業(yè)指導(dǎo)課程 )全套教學(xué)課件
- 死亡病例討論總結(jié)分析
- 第二章 會展的產(chǎn)生與發(fā)展
- 空域規(guī)劃與管理V2.0
- JGT266-2011 泡沫混凝土標(biāo)準(zhǔn)規(guī)范
- 商戶用電申請表
評論
0/150
提交評論