while循環(huán)結(jié)構(gòu)例題.doc_第1頁(yè)
while循環(huán)結(jié)構(gòu)例題.doc_第2頁(yè)
while循環(huán)結(jié)構(gòu)例題.doc_第3頁(yè)
while循環(huán)結(jié)構(gòu)例題.doc_第4頁(yè)
while循環(huán)結(jié)構(gòu)例題.doc_第5頁(yè)
已閱讀5頁(yè),還剩30頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

引子#include stdio.hmain() int i=1; for(i=1;i=10000;i+) printf(“%dt”,i);題型1 輸入輸出多個(gè)數(shù)據(jù)eg1、輸出110000之間所有的整數(shù)#include stdio.hmain() int i=1; while(i=1000) printf(“%dt”,i); i+;拓展:1、換成所有的奇數(shù) 2、換成所有的偶數(shù)題型2 有限個(gè)數(shù)連加和連乘eg2.1、求1+2+3+4+100的值#include stdio.hmain() int i=1,s=0; 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.hmain() 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.hmain() int i=1,n,p=1,s; scanf(“%d”,&n); while(i=1e-4) t=f/(2*n-1); s=s+t;f=-f;n+;printf(“%fn”,s);拓展:求1-1/2+1/4-1/6+的近似值,要求精度要達(dá)到10-4題型4 統(tǒng)計(jì)eg4.1、輸入20個(gè)數(shù),統(tǒng)計(jì)其中正數(shù)、負(fù)數(shù)和零的個(gè)數(shù)。#include stdio.hmain() int i=1,n,p,z; float x; p=n=z=0; while(i0)p+; else if(x0) n+;else z+; i+;printf(“%dt%dt %dn”,p,n,z);拓展:統(tǒng)計(jì)各類(lèi)字符的個(gè)數(shù)eg4.2 個(gè)位為6且能被3整除的五位數(shù)有多少?方法1#include stdio.hmain() long i=10000,c=0; while(i=99999) if(i%3=0)& (i%10=6)c+;i+;printf(“%d n”,c);方法2#include stdio.hmain() 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.hmain() int f1=1,f2=1, f3,i=3; while(i=20) f3=f1+f2;f1=f2;f2=f3;i+;printf(“%d n”,f3);拓展:輸出fibo數(shù)列前20位數(shù)字#include stdio.hmain() int f1=1,f2=1, f3,i=3;printf(“%d t%d t”,f1,f2); while(in) 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 素?cái)?shù)問(wèn)題eg8 從鍵盤(pán)上任意輸入一個(gè)正整數(shù),判斷其是否為素?cái)?shù)。#include stdio.hmain() 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.hmain()float x1=10,x2=-10,x, y ,y1;x=(x1+x2)/2;y=2*x*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*y10) 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.hmain()float x,x0, y ,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.hmain() 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.hmain() int i=1,s=0; for(i=1;i=100;i+) s=s+i; printf(“%dn”,s);f2#include stdio.hmain( )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.hmain( )int i;float a,max;scanf(%f ,&a);max=a;for(i=1;i=9;i+) scanf(%f ,&a); if(maxa) max=a;printf(%fn,max);f4#include stdio.hmain( )int i,s=1;for(i=9;i=1;i-)s=2*(s+1);printf(%dn,s);#include stdio.hmain()int x,n=0,s=0; while (n10) scanf(%d,&x); if (x0) break; s+=x; n+; printf(s=%dn,s); #include stdio.hmain( )int x,n=0,s=0;while (n10) scanf(%d,&x); if (x0) continue; s+=x; n+; printf(s=%dn,s);#include stdio.hmain( )int x,n=0,s=0;while (n10) scanf(%d,&x);n+; if (x0) continue; s+=x; printf(s=%dn,s);#include stdio.hmain()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.hmain()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.hmain( ) int i,m; scanf(%d,&m); for (i=2; i=m; i+) if (m%i=0) break; if(i=m) printf(%d shi sushu!n,m); else printf(%d bu shi sushu!n,m);#include stdio.h#include math.hmain( ) 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,m);#include stdio.h#include math.hmain() 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.hmain() int i,j,s; for(i=100;i=200;i+) s=sqrt(i); for(j=2;j=s;j+) if (i%j=0) break; if(j=s+1) printf(%-10d,i); #include main( ) int i,j,s; for (i=2; i=10000; i+) s=0; for (j=1; ji; j+) if (i%j=0) s+=j; if (i=s) printf(%6dn,s); #include stdio.hmain()int i,j,k;for(i=0;i=35;i+) for(j=0;j=35;j+) if(i+j=35)&(2*i+4*j=94) printf(ni=%-10dj=%-10d,i,j); #include stdio.hmain() 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.hmain() 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.hmain() 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,i,j,k); #include stdio.hmain() 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.hmain()int i; for(i=1;i=5;i+)printf(*n); #include stdio.hmain()int i,j; for(i=1;i=5;i+) for(j=1;j=5-i;j+) printf( ); printf(*n); #include stdio.hmain( ) 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.hmain() 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); #include stdio.h main( ) int i,j; for (i=1; i=5; i+) for (j=1; j=i-1; j+) printf( ); for (j=1;j=11-2*i;j+) printf(*); printf(n); #include stdio.hmain( ) int i,j; for (i=1; i=4; i+) for (j=1; j=4-i; j+) printf( );

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論