1 / 13

重複迴圈 while

重複迴圈 while. while 敘述的使用格式:. while( 條件運算式 ) { 敘述區塊 ; }. // 九九乘法表 1*1=1 1*2=2 1*3=3 1*4=4……………………..1*9=9. // 九九乘法表 # include <iostream.h> void main() { int i,j,k; i=1; j=1; while (j<10) { k=I*j; cout<<i<<“ *”<<j<<“=“<<k; j++; } }. 如何做兩個迴圈,完整呈現九九乘法表.

Download Presentation

重複迴圈 while

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 重複迴圈while • while 敘述的使用格式: while(條件運算式) { 敘述區塊; }

  2. //九九乘法表 1*1=1 1*2=2 1*3=3 1*4=4……………………..1*9=9

  3. //九九乘法表 # include <iostream.h> void main() { int i,j,k; i=1; j=1; while (j<10) { k=I*j; cout<<i<<“*”<<j<<“=“<<k; j++; } }

  4. 如何做兩個迴圈,完整呈現九九乘法表

  5. 九九乘法表 k值可能是個位數,也可能是十位數,如何對齊?

  6. //說出此程式輸出結果 # include <iostream.h> void main() { int i,j; i=1; j=1; while(i<=5) { while (j<=i) { cout<<j; j++; } cout<<“\n”; j=1; i++; } }

  7. 設計一程式,輸出結果為 1 22 333 4444 55555

  8. 設計一程式,輸出結果為 1 12 123 1234 12345

  9. //說出此程式輸出結果 # include <iostream.h> void main() { int i,j; i=1; j=1; while(i<=5) { while (j<=i) //這裡讓它重複五次 { cout<<j; j++; } cout<<“\n”; j=1; i++; } }

  10. //說出此程式輸出結果 # include <iostream.h> void main() { int i,j; i=1; j=1; while(i<=5) { while (j<=5) //前四次輸出一空白 { cout<<j; //這裡如何加上if…else 敘述 j++; //if 條件成立輸出j 不成立輸出空白 } cout<<“\n”; j=1; i++; } }

  11. //說出此程式輸出結果 # include <iostream.h> void main() { int i,j,k,n; i=1;j=1;n=5; while(i<=n) { while (j<=n) { if(j>=(n-i+1)) cout<<j+i-n; else cout<<“ “; j++; } cout<<“\n”; j=1; i++; } }

  12. //求50以內的所有正質數 # include <iostream.h> void main() { int i,j,n; i=2; j=2; n=50; while(i<=n) { while (j<i) { if(i%j==0)break; j++; } if (j==i)cout<<i<<“,”; j=2; i++; } }

  13. 1. 設計程式計算n階層 1!=1 2!=2 3!=6 2.輸入一個正整數,列出其質因數的成積,如12=2*2*3 3.設計一程式列印出 0123456789 1234567890 2345678901 ….. ….. 9012345678 進階 1234 2341 3412 4123

More Related