版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、2.2#include<stdio.h>main()floatx=2.5,y=2.5,z=2.5;printf("x=%fn",x);printf("y=%fn",y);printf("z=%fn",z);3.1(1)#include<stdio.h>main()inta=12,b=3;floatx=18.5,y=4.6;printf("%fn",(float)(a*b)/2);printf("%dn",(int)x%(int)y);3.1(2)#include<s
2、tdio.h>main().'intx=32,y=81,p,q;p=x+;q=-y;printf("%d%dn",p,q);printf("%d%dn",x,y);3.2#include<stdio.h>main()intx,b0,b1,b2,s;printf("Inputx:");scanf("%d",&x);b2=x/100;b1=(x-b2*100)/10;/或(x%100)/10;或x/10%10;b0=x%10;s=b0*100+b1*10+b2;printf("
3、;s=%dn",s);3.3#include<stdio.h>#include<math.h>main()floatrate=0.0225;floatn,capital,deposit;printf("Inputn,capital:");scanf("%f,%f",&n,&capital);deposit=capital*pow(1+rate,n);printf("deposit=%fn",deposit);3.4#include<stdio.h>#include<m
4、ath.h>main()floata,b,c;doublex,y;printf("Inputa,b,c:");scanf("%f%f%f",&a,&b,&c);x=(-b+sqrt(b*b-4*a*c)/(2*a);y=(-b-sqrt(b*b-4*a*c)/(2*a);printf("x=%f,y=%fn",x,y);習(xí)題44.1(1)#include<stdio.h>main()charc1='a',c2='b',c3='c'printf(&
5、quot;a%cb%cc%cn",c1,c2,c3);4.1(2)#include<stdio.h>main()inta=12,b=15;printf("a=%d%,b=%d%n”,a,b);一4.1(3)#include<stdio.h>main()inta,b;scanf("%2d%*2s%2d",&a,&b);printf("%d,%dn",a,b);4.2#include<stdio.h>main()longa,b;floatx,y;scanf("%d,%dn&qu
6、ot;,&a,&b);scanf("%f,%fn",&x,&y);printf("a=%d,b=%dn",a,b);printf("x=%f,b=%fn",x,y);5.1#include<stdio.h>main()floata;printf("Inputa:");scanf("%f",&a);if(a>=0)a=a;printf("a=%fn",a);elsea=-a;printf("a=%fn"
7、;,a);5.2#include<stdio.h>main()inta;printf("Inputa:");scanf("%d",&a);if(a%2=0)printf("a是偶數(shù))elseprintf("a是奇數(shù))5.3#include<stdio.h>#include<math.h>main()floata,b,c,s,area;printf("Inputa,b,c:");scanf("%f%f%f",&a,&b,&c);i
8、f(a+b>c&&a+c>b&&b+c>a)s=(a+b+c)/2;area=(float)sqrt(s*(s-a)*(s-b)*(s-c);printf("area=%fn",area);elseprintf("不是三角形");5.4#include<stdio.h>#include<math.h>main()floata,b,c,x,y;printf("Inputa,b,c:");scanf("%f,%f,%f",&a,&
9、b,&c);if(a=0)printf("該方程不是一元二次方程n");if(b*b-4*a*c>0)x=(-b+sqrt(b*b-4*a*c)/(2*a);y=(-b-sqrt(b*b-4*a*c)/(2*a);printf("x=%f,y=%fn",x,y);elseif(b*b-4*a*c=0)x=-b/(2*a);y=-b/(2*a);printf("x=%f,y=%fn",x,y);elseprintf("該方程無實(shí)根n");5.5#include<stdio.h>main()i
10、ntyearflag;printf("Inputayear:");scanf("%d”,&year);if(year%4=0&&year%400!=0|year%400=0)flag=1;elseflag=0;if(flag=1)printf("%disaleapyear!n",year);elseprintf("%disnotaleapyear!n",year);5.6#include<stdio.h>main()intyearflag;printf("Inputayear:&
11、quot;);scanf("%d”,&year);flag=year%400=0|year%4=0&&year%100!=0?1:0;if(flag=1&&flag!=0)printf("%disaleapyear!n",year);elseprintf("%disnotaleapyear!n",year);5.7#include<stdio.h>main()charch;printf("Inputch:");scanf("%c",&ch);if
12、(ch>='a'&&ch<='z')ch=getchar();ch=ch-32;printf("%c,%dn",ch,ch);elseif(ch>='A'&&ch<='Z')ch=getchar();ch=ch+32;printf("%c,%dn",ch,ch);elseprintf("%c",ch);5.8#include<stdio.h>main()charch;printf("Inputc
13、h:");scanf("%c",&ch);if(ch>=48&&ch<=57)printf("ch是數(shù)字字符n");elseif(ch>=65&&ch<=90)printf("ch是大寫字母n");elseif(ch>=97&&ch<=122)printf("ch是小寫字母n");elseif(ch=32)printf("ch是空格n");elseprintf("ch是其他字符n&qu
14、ot;);5.9#include<stdio.h>main()intscore,grade;printf("Inputscore:");scanf("%d”,&score);grade=score/10;if(score<0|score>100)printf("Inputerrorn");if(score>=90&&score<=100)printf("%d-An",score);elseif(score>=80&&score<90)pr
15、intf("%d-Bn",score);elseif(score>=70&&score<80)printf("%d-Cn",score);elseif(score>=60&&score<70)printf("%d-Dn",score);elseif(score>=0&&score<60)printf("%d-En",score);5.10#include<stdio.h>main()intyear,month;print
16、f("Inputyear,month:");scanf("%d,%d",&year,&month);if(month>12|month<=0)printf("errormonthn");-i:I'l1-elseswitch(year,month)case12:I.case10:case8:case7:case5:case3:case I:printf("31天n");break;case II:case9:case6:case4:printf("30天n");
17、break;case2:if(year%4=0&&year!=0|year%400=0)printf("29天n");elseprintf("28天n");break;default:printf("Inputerrorn");6.1(1)#include<stdio.h>main()inti,j,k;charspace=''for(i=1;i<=4;i+)for(j=1;j<=i;j+)printf("%c",space);for(k=1;k<=6;k
18、+)printf("*");printf("n");6.1(2)#include<stdio.h>main()intk=4,n;for(n=0;n<k;n+)if(n%2=0)continue;k-;printf("k=%dn,n=%dn",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=%dn",k,n);6.2(1)#include<st
19、dio.h>main()inti,sum=0;for(i=1;i<=101;i+)sum=sum+i;printf("sum=%dn",sum);6.2(2)#include<stdio.h>main()longi;j1-longterm,sum=0;for(i=1;i<=101;i=i+2)term=i*(i+1)*(i+2);sum=sum+term;printf("sum=%ldn”,sum);6.2(4)#include<stdio.h>#include<math.h>main()intn=1;floa
20、tterm=1.0,sign=1,sum=0;while(term<=-1e-4|term>=1e-4)term=1.0/sign;sum=sum+term;sign=sign+n;n+;printf("sum=%fn",sum);6.2 (5)#include<stdio.h>#include<math.h>main()intn=1,count=1;floatx;doublesum,term;printf("Inputx:");scanf("%f",&x);sum=x;term=x;dot
21、erm=-term*x*x/(n+1)*(n+2);sum=sum+term;n=n+2;count+;while(fabs(term)>=1e-5);printf("sin(x)=%f,count=%dn",sum,count);6.3 #include<stdio.h>main()-.IlI''l1-;intx=1,find=0;while(!find)if(x%2=1&&x%3=2&&x%5=4&&x%6=5&&x%7=0)printf("x=%dn"
22、,x);find=1;x+;/*intx,find=0;for(x=1;!find;x+)if(x%2=1&&x%3=2&&x%5=4&&x%6=5&&x%7=0)printf("x=%dn",x);find=1;*/6.4 #include<stdio.h>main()inti,n;longp=1,m=1;printf("Inputn:");scanf("%d",&n);for(i=1;i<=n;i+)p=i*i;m=i*i*i;printf(
23、"p=%d,m=%dn",i,p,i,m);6.5 #include<stdio.h>main()floatc,f;for(c=-40;c<=110;c=c+10)f=9/5*c+32;printf("f=%fn",f);6.6 #include<stdio.h>#include<math.h>main()Iintn;doublec=0.01875,x;dox=x*pow(1+c,12)-1000;n+;while(x>0);printf("x=%dn",x);6.7 #include&
24、lt;stdio.h>main()intn=0;floata=100.0,c;printf("Inputc:");scanf("%f",&c);doa=a*(1+c);n+;while(a<=200);printf("n=%dn",n);6.8 #include<stdio.h>#include<math.h>main()intn=1,count=1;doublesum=1,term=1;while(fabs(term)>=1e-5)term=pow(-1,count)*(1.0/(n
25、+2);sum=sum+term;n=n+2;count+;r-,、工、,圮、產(chǎn)Isum=4*sum;-1"I'l,-!printf("sum=%f,count=%dn",sum,count);6.9 #include<stdio.h>#include<math.h>main()intn=1,count=1;doublesum=1,term=1;while(fabs(term)>=1e-5)term=term*(1.0/n);sum=sum+term;n+;count+;printf("sum=%f,count=%d
26、n",sum,count);6.10 #include<stdio.h>#include<math.h>main()intx;for(x=100;x<=999;x+)if(x=pow(x/100,3)+pow(x/10%10,3)+pow(x%10,3)printf("x=%dn",x);6.11 #include<stdio.h>main()inti=0,n;longsum=0,term=1;printf("Inputn:");scanf("%d",&n);doi+;ter
27、m=term*i;sum=sum+term;while(sum<n);printf("%dn",i-1);r-'葭%XXs'/*I6.12 #include<stdio.h>一一、.l1"I'l,-'">main()inti,n,m,count=0,sum=0;printf("Inputn:");scanf("%d",&n);for(i=1;i<=n;i+)Iprintf("Inputm:");scanf("%d&q
28、uot;,&m);if(m>0)sum=sum+m;count+;elsebreak;printf("sum=%d,count=%dn",sum,count);)6.13 #include<stdio.h>main()(inti,n,m,count=0,sum=0;printf("Inputn:");scanf("%d",&n);for(i=1;i<=n;i+)(printf("Inputm:");scanf("%d",&m);if(m>0|
29、m<0)(sum=sum+m;count+;)else(break;)printf("sum=%d,count=%dn",sum,count);)r-yV立JX.J!I)6.14 #include<stdio.h>"j''i1-:、main()(intx,y,z;for(x=0;x<=17;x+)for(y=0;y<=25;y+)3*x+2*y+z=50;z=30-x-y;if(3*x+2*y+z=50&&x+y+z=30)printf("x=%d,y=%d,z=%dn",x,y,z
30、);)6.15 #include<stdio.h>main()intx,y;for(x=0;x<=98;x+)y=98-x;2*x+4*y=386;if(x+y=98&&2*x+4*y=386)(printf("x=%d,y=%dn",x,y);)6.16 #include<stdio.h>main()(intx,y,z;for(x=0;x<=20;x+)(for(y=0;y<=33;y+)(3*y+5*x+z/3.0=100;z=100-x-y;if(5*x+3*y+z/3.0=100&&z+x+y
31、=100)(printf("x=%d,y=%d,z=%dn",x,y,z);)r-y5立b"rXX/!I)-i''i1);)6.17#include<stdio.h>main()intx,y,z;for(x=1;x<=9;x+)(for(y=1;y<=17;y+)(10*x+5*y+z=100;z=50-x-y;if(10*x+5*y+z=100&&x+y+z=50&&z>0)(printf("x=%d,y=%d,z=%dn",x,y,z);)7.1 #include
32、<stdio.h>intSquare(inti)returni*i;intmain()inti=0;i=Square(i);for(;i<3;i+)staticinti=1;i+=Square(i);printf("%d,",i);printf("%dn",i);return0;7.2 #include<stdio.h>inthour,minute,second;voidupdate()second+;if(second=60)''lIsecond=0;minute+;if(minute=60)minute=
33、0;hour+;if(hour=24)hour=0;voiddisplay。printf("%d,%d,%dn",hour,minute,second);voiddelay()intt;for(t=0;t<100000000;t+);intmain()inti;voidupdaye(),display(),delay();for(i=0;i<1000000;i+)update();display。;delay();return0;7.3 #include<stdio.h>intGetMax(inta,intb);intmain()intx,y,max
34、;printf("Inputx,y:");scanf("%d,%d",&x,&y);max=GetMax(x,y);printf("max=%dn",max);return0;'l,-intGetMax(intm,intn)if(m>=n)returnm;elseI.returnn;7.4 #include<stdio.h>intLCM(intn,intm);intmain()inta,b;printf("Inputa,b:");scanf("%d,%d"
35、;,&a,&b);printf("%dn",LCM(a,b);return0;intLCM(intn,intm)intx;intfind=0;for(x=1;!find;x+)if(x%n=0&&x%m=0)find=1;returnx-1;7.5 #include<stdio.h>longFact(intn);intmain()intm,a;printf("Inputm:");scanf("%d",&m);for(a=1;a<=m;a+)printf("%d!=%ldn",a,Fact(a);return0;i1,"l1IlongFact(intn)inti;longresult=1;for(i=2;i<=n;i+)Iresult*=i;returnresult;7.6#include<stdio.h>longFact(intn);intmain(
溫馨提示
- 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)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度殯儀館遺體告別儀式策劃及執(zhí)行服務(wù)協(xié)議3篇
- 2025年全球及中國農(nóng)業(yè)機(jī)械專用履帶行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報告
- 2025年度集裝箱板房行業(yè)競爭策略研究合同3篇
- 2025-2030全球無線遠(yuǎn)傳智能水表行業(yè)調(diào)研及趨勢分析報告
- 二零二五年度國際合同第六號生皮可持續(xù)發(fā)展戰(zhàn)略合作伙伴協(xié)議2篇
- 2025-2030全球自動原子力顯微鏡行業(yè)調(diào)研及趨勢分析報告
- 2025-2030全球軟膜低頻陷阱行業(yè)調(diào)研及趨勢分析報告
- 2025年我愛我家二手房購房中介委托服務(wù)協(xié)議6篇
- 二零二五版?zhèn)€人裝修貸款合同范本范例3篇
- 二零二五年度建筑設(shè)備安裝工程勞務(wù)分包合同規(guī)范3篇
- 插圖在小學(xué)英語口語教學(xué)中的運(yùn)用
- 前列腺增生藥物治療
- 人工智能知識圖譜(歸納導(dǎo)圖)
- 滴滴補(bǔ)貼方案
- 民宿建筑設(shè)計(jì)方案
- 干部基本信息審核認(rèn)定表
- 2023年11月外交學(xué)院(中國外交培訓(xùn)學(xué)院)2024年度公開招聘24名工作人員筆試歷年高頻考點(diǎn)-難、易錯點(diǎn)薈萃附答案帶詳解
- 春節(jié)行車安全常識普及
- 電機(jī)維護(hù)保養(yǎng)專題培訓(xùn)課件
- 汽車租賃行業(yè)利潤分析
- 春節(jié)拜年的由來習(xí)俗來歷故事
評論
0/150
提交評論