1 / 11

第 7 章 for( ループ応用 );

第 7 章 for( ループ応用 );. ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ!. 前回の C++ 講座. for でも while と同じようにループが作れる! for 難しい …. 練習問題. 実行結果と同じになるようにプログラムを書いてください プログラムは入力した値が素数かどうかを調べています. 解答. for(int i=2;i<n;i++)

lee-winters
Download Presentation

第 7 章 for( ループ応用 );

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. 第7章for(ループ応用); ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ! ループだよ!

  2. 前回のC++講座 • forでもwhileと同じようにループが作れる! • for難しい… 第7章 ループ

  3. 練習問題 実行結果と同じになるようにプログラムを書いてください プログラムは入力した値が素数かどうかを調べています 第7章 ループ

  4. 解答 for(int i=2;i<n;i++) if(n%i==0){ printf(“素数では ありません\n"); return 0; } printf(“素数です\n”); return 0; } #include<stdio.h> int main(){ int n; printf("Input n > "); scanf("%d",&n); if(n==1){ printf("素数では ありません\n"); return 0; } if(n==2){ printf(“素数です\n"); return 0; } 第7章 ループ

  5. 九九計算表 %4d 『_ _49_ _ 56』 ↑表にした時に見やすい %d 『4956』 ↑空白が詰められるから見にくい #include<stdio.h> int main(){ int i,j; for(i=1;i<10;i++){ for(j=1;j<10;j++) printf("%4d",i*j); printf("\n"); } return 0; } 第7章 ループ

  6. 面積 #include<stdio.h> int main(){ int tate,yoko; int i,j; printf("縦 > "); scanf("%d",&tate); printf("横 > "); scanf("%d",&yoko); for(i=0;i<tate;i++){ for(j=0;j<yoko;j++) printf(“(´・ω・`)"); printf("\n"); } return 0; } 第7章 ループ

  7. 練習問題 実行結果と同じになるようにプログラムを書いてください プログラムは入力した値を2辺に持つ角が左下にある直角二等辺三角形を出力しています ↓暇な人はこちら 第7章 ループ

  8. 解答 #include<stdio.h> int main(){ int length; int i,j; printf(“2辺の長さ3 > "); scanf("%d",&length); for(i=0;i<length;i++){ for(j=0;j<=i;j++) printf(“☆"); printf("\n"); } return 0; } #include<stdio.h> int main(){ int length; int i,j; printf(“2辺の長さ3 > "); scanf("%d",&length); for(i=0;i<length;i++){ for(j=0;j<=length-i;j++) printf(“☆"); printf("\n"); } return 0; } 第7章 ループ

  9. 練習問題 実行結果と同じになるようにプログラムを書いてください プログラムは入力した値を2辺に持つ角が右下にある直角二等辺三角形を出力しています            ↓暇なひとはこちら 第7章 ループ

  10. 解答 #include<stdio.h> int main(){ int length; int i,j; printf(“2辺の長さ > "); scanf("%d",&length); for(i=0;i<length;i++){ for(j=1;j<length-i;j++) printf(" "); for(j=0;j<=i;j++) printf("☆"); printf("\n"); } return 0; } #include<stdio.h> int main(){ int length; int i,j; printf(“段の数 > "); scanf("%d",&length); for(i=0;i<length;i++){ for(j=1;j<length-i;j++) printf(" "); for(j=0;j<i*2+1;j++) printf("☆"); printf("\n"); } return 0; } 第7章 ループ

  11. 次回 配列 一度にたくさん変数作れる!便利! 第7章 ループ

More Related