




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、引子#include "stdio.h"main() int i=1; for(i=1;i<=10000;i+) printf(“%dt”,i);題型1 輸入輸出多個數(shù)據(jù)eg1、輸出110000之間所有的整數(shù)#include "stdio.h"main() int i=1; while(i<=1000) printf(“%dt”,i); i+;拓展:1、換成所有的奇數(shù) 2、換成所有的偶數(shù)題型2 有限個數(shù)連加和連乘eg2.1、求1+2+3+4+100的值#include "stdio.h"main() int i=1,s=0
2、; while(i<=100) s=s+i;i+;printf(“%dn”,s);拓展:1、求1+2+3+4+n的值2、求12+22+32+n2的值 3、求1+1/2+1/3+1/n的值eg2.2、求n!的值#include "stdio.h"main() int i=1,n,p=1; scanf(“%d”,&n); while(i<=n) p=p*i;i+;printf(“%dn”,p);拓展:求1!+2!+3!+n!的值#include "stdio.h"main() int i=1,n,p=1,s; scanf(“%d”,&am
3、p;n); while(i<=n) p=p*i; s=s+p;i+;printf(“%dn”,s);題型3 無限個數(shù)連加eg3、求1-1/3+1/5-1/7+的近似值,要求精度要達到10-4#include "stdio.h"#include "math.h"main() float n=1,s=0,f=1,t=1; while(fabs(t)>=1e-4) t=f/(2*n-1); s=s+t;f=-f;n+;printf(“%fn”,s);拓展:求1-1/2+1/4-1/6+的近似值,要求精度要達到10-4題型4 統(tǒng)計eg4.1、輸入20
4、個數(shù),統(tǒng)計其中正數(shù)、負數(shù)和零的個數(shù)。#include "stdio.h"main() int i=1,n,p,z; float x; p=n=z=0; while(i<=20) scanf(“%f”,&x);if(x>0)p+; else if(x<0) n+;else z+; i+;printf(“%dt%dt %dn”,p,n,z);拓展:統(tǒng)計各類字符的個數(shù)eg4.2 個位為6且能被3整除的五位數(shù)有多少?方法1#include "stdio.h"main() long i=10000,c=0; while(i<=999
5、99) if(i%3=0)&& (i%10=6)c+;i+;printf(“%d n”,c);方法2#include "stdio.h"main() long i=10006,c=0; while(i<=99999) if(i%3=0)c+;i=i+10;printf(“%d n”,c);題型5 數(shù)列eg5 輸出fibo數(shù)列的第20位數(shù)字#include "stdio.h"main() int f1=1,f2=1, f3,i=3; while(i<=20) f3=f1+f2;f1=f2;f2=f3;i+;printf(“%d
6、n”,f3);拓展:輸出fibo數(shù)列前20位數(shù)字#include "stdio.h"main() int f1=1,f2=1, f3,i=3;printf(“%d t%d t”,f1,f2); while(i<=20) f3=f1+f2;f1=f2;f2=f3; printf(“%d t”,f3);i+;題型6 數(shù)據(jù)的逆序輸出eg6 任意給定一個正整數(shù),個位數(shù)字逆序輸出。#include "stdio.h"main() long x,t; scanf(“%ld”,&x); while(x!=0) t=x%10;x=x/10;printf(“
7、%d”,t); 題型7 公約數(shù)與公倍數(shù)eg7 任意輸入兩個正整數(shù),求其最大公約數(shù)和最小公倍數(shù)。#include "stdio.h"main() int m,n,a,b,r,t; scanf(“%d%d”,&m, &n); if(m>n) a=m;b=n; else a=n;b=m; while(b!=0) r=a%b;a=b;b=r;printf(“zuida gongyushu shi:%dn”,a);printf(“zuixiao gongbeishu shi:%dn”,m*n/a);題型8 素數(shù)問題eg8 從鍵盤上任意輸入一個正整數(shù),判斷其是否為
8、素數(shù)。#include "stdio.h"main() int x,i=2; scanf(“%d”,&x); while(x%i!=0) i+; if(x=i) printf(“shi!”);else printf(“fou!”);題型9 高次方程的根eg9.1 用二分迭代法求解方程y=2x3-4x2+3x-6=0在(-10,10)之間的根,要求精度10-5#include "stdio.h"#include "math.h"main()float x1=10,x2=-10,x, y ,y1;x=(x1+x2)/2;y=2*x
9、*x*x-4*x*x+3*x-6;while(fabs(y)>1e-5)y1=2*x1*x1*x1-4*x1*x1+3*x1-6; if(y*y1>0) x1=x; else x2=x; x=(x1+x2)/2; y=2*x*x*x-4*x*x+3*x-6; printf("the root is %fn",x);eg9.2 用牛頓迭代法求解方程2x3+ 4x2-7x-6=0在x=1.5附近的根,要求精度10-5#include "stdio.h"#include "math.h"main()float x,x0, y ,
10、y1;x=1.5;while(fabs(x-x0)>1e-5) x0=x;y=2*x0*x0*x0+4*x0*x0-7*x0-6;y1=6*x0*x0+8*x0-7;x=x0-y/y1;printf("the root is %fn",x);牛頓迭代公式:xn+1=xn-f(xn)/f(xn)do-while循環(huán)結(jié)構(gòu)舉例#include "stdio.h"main() int i=1,s=0; do s=s+i;i+; while(i<=100);printf(“%dn”,s);for循環(huán)結(jié)構(gòu)舉例f1#include "stdio.
11、h"main() int i=1,s=0; for(i=1;i<=100;i+) s=s+i; printf(“%dn”,s);f2#include "stdio.h"main( )int i,f1,f2,f3;f1=1;f2=1;printf("%d,%d",f1,f2);for(i=3;i<=20;i+) f3=f1+f2; f1=f2; f2=f3; printf(",%d",f3);f3#include "stdio.h"main( )int i;float a,max;scanf(&
12、quot;%f ",&a);max=a;for(i=1;i<=9;i+) scanf("%f ",&a); if(max<a) max=a;printf("%fn",max);f4#include "stdio.h"main( )int i,s=1;for(i=9;i<=1;i-)s=2*(s+1);printf("%dn",s);#include "stdio.h"main()int x,n=0,s=0; while (n<10) scanf(
13、"%d",&x); if (x<0) break; s+=x; n+; printf("s=%dn",s); #include "stdio.h"main( )int x,n=0,s=0;while (n<10) scanf("%d",&x); if (x<0) continue; s+=x; n+; printf("s=%dn",s);#include "stdio.h"main( )int x,n=0,s=0;while (n<10
14、) scanf("%d",&x);n+; if (x<0) continue; s+=x; printf("s=%dn",s);#include "stdio.h"main()int i=2,m; scanf("%d",&m);while(m%i!=0)i+;if(i=m) printf("%d shi sushu!n",m); else printf("%d bu shi sushu!n",m);#include "stdio.h"
15、main()int i,m;scanf("%d",&m);for(i=2;m%i!=0;i+) ;if(i=m) printf("%d shi sushu!n",m);else printf("%d bu shi sushu!n",m);#include "stdio.h"main( ) int i,m; scanf("%d",&m); for (i=2; i<=m; i+) if (m%i=0) break; if(i=m) printf("%d shi sus
16、hu!n",m); else printf("%d bu shi sushu!n",m);#include "stdio.h"#include "math.h"main( ) int i,m,s; scanf("%d",&m); s=sqrt(m); for (i=2; i<=s; i+) if (m%i=0) break; if(i=s+1) printf("%d shi sushu!n",m); else printf("%d bu shi sushu!n&
17、quot;,m);#include "stdio.h"#include "math.h"main() int i,j; for(i=100;i<=200;i+) for(j=2;j<=i;j+) if (i%j=0) break; if(j=i) printf("%-10d",i); #include "stdio.h"#include "math.h"main() int i,j,s; for(i=100;i<=200;i+) s=sqrt(i); for(j=2;j<
18、=s;j+) if (i%j=0) break; if(j=s+1) printf("%-10d",i); #include <include.h>main( ) int i,j,s; for (i=2; i<=10000; i+) s=0; for (j=1; j<i; j+) if (i%j=0) s+=j; if (i=s) printf("%6dn",s); #include "stdio.h"main()int i,j,k;for(i=0;i<=35;i+) for(j=0;j<=35;j
19、+) if(i+j=35)&&(2*i+4*j=94) printf("ni=%-10dj=%-10d",i,j); #include "stdio.h"main() int i,j,k; for(i=0;i<=19;i+) for(j=0;j<=33;j+) for(k=0;k<=100;k+) if(i+j+k=100)&&(5*i+3*j+k/3=300) printf("ni=%-10dj=%-10dk=%-10d",i,j,k);#include "stdio.h&
20、quot;main() int i,j,k;for(i=0;i<=19;i+)for(j=0;j<=33;j+) k=100-i-j; if(15*i+9*j+k=300) printf("ni=%-10dj=%-10dk=%-10d",i,j,k); #include "stdio.h"main() int i,j,k; for(i=0;i<=19;i+) for(j=0;j<=33;j+) k=100-i-j; if(5*i+3*j+k/3=100) printf("ni=%-10dj=%-10dk=%-10d&qu
21、ot;,i,j,k); #include "stdio.h"main() int m,n,k; for (m=1;m<=9;m+) for(n=1;n<=m;n+) printf("%d*%d=%-5d",n,m,n*m); printf("n"); #include "stdio.h"main()int i; for(i=1;i<=5;i+)printf("*n"); #include "stdio.h"main()int i,j; for(i=1;i&l
22、t;=5;i+) for(j=1;j<=5-i;j+) printf(" "); printf("*n"); #include "stdio.h"main( ) int i,j; for (i=1; i<=5; i+) for (j=1; j<=20-i; j+) printf(" "); for (j=1;j<=i;j+) printf("*"); printf("n"); #include "stdio.h"main() int i,j; for (i=1;i<=5;i+) for (j=1;j<=20-i;j+) printf(" "); for (j=1;j<=2*i-1;j+) printf("*"); printf("n"); #includ
溫馨提示
- 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)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 無錫科技職業(yè)學(xué)院《小學(xué)數(shù)學(xué)基礎(chǔ)理論》2023-2024學(xué)年第二學(xué)期期末試卷
- 湖南中醫(yī)藥高等專科學(xué)?!痘み^程開發(fā)與設(shè)計》2023-2024學(xué)年第二學(xué)期期末試卷
- 保山中醫(yī)藥高等??茖W(xué)校《材料智能裝備學(xué)實驗》2023-2024學(xué)年第二學(xué)期期末試卷
- 遼寧機電職業(yè)技術(shù)學(xué)院《跨境電商模擬》2023-2024學(xué)年第二學(xué)期期末試卷
- 襄陽職業(yè)技術(shù)學(xué)院《電子商務(wù)A》2023-2024學(xué)年第二學(xué)期期末試卷
- 鞍山師范學(xué)院《數(shù)字電視中心技術(shù)》2023-2024學(xué)年第二學(xué)期期末試卷
- 重慶傳媒職業(yè)學(xué)院《化學(xué)分離與富集》2023-2024學(xué)年第二學(xué)期期末試卷
- 湄洲灣職業(yè)技術(shù)學(xué)院《數(shù)碼圖形處理》2023-2024學(xué)年第二學(xué)期期末試卷
- 桂林師范高等??茖W(xué)?!栋婷嬖O(shè)計》2023-2024學(xué)年第二學(xué)期期末試卷
- 蘭州航空職業(yè)技術(shù)學(xué)院《通風(fēng)工程》2023-2024學(xué)年第二學(xué)期期末試卷
- 車輛采購、維修服務(wù)投標(biāo)方案
- 藥劑科病房麻醉藥品精神藥品處方流程
- 營銷策劃模版課件
- 智慧樓宇設(shè)計方案.pdf
- 外架懸挑防護棚施工方案完整
- (精選)社區(qū)管理網(wǎng)上形成性考核作業(yè)
- 以天然氣制合成氣的工藝
- 設(shè)備計算與選型——孫景海
- 恩格勒系統(tǒng)整理17頁
- JGJ_T487-2020建筑結(jié)構(gòu)風(fēng)振控制技術(shù)標(biāo)準(zhǔn)(高清-最新版)
- 《交通工程學(xué)》PPT
評論
0/150
提交評論