Microsoft PowerPoint - program.ppt [互換モード]

Similar documents
<4D F736F F D20438CBE8CEA8D758DC F0939A82C282AB2E646F63>

PowerPoint プレゼンテーション

4 分岐処理と繰返し処理 ( 教科書 P.32) プログラムの基本的処理は三つある. (1) 順次処理 : 上から下に順番に処理する ぶんきそろ (2) 分岐処理 : 条件が揃えば, 処理する はんぷく (3) 反復処理 : 条件が揃うまで処理を繰り返す 全てのプログラムは (1) から (3) の

kiso2-09.key

Microsoft Word - 3new.doc

gengo1-2

初歩のC言語ターミナル_2014_May.pages

PowerPoint プレゼンテーション

char int float double の変数型はそれぞれ 文字あるいは小さな整数 整数 実数 より精度の高い ( 数値のより大きい より小さい ) 実数 を扱う時に用いる 備考 : 基本型の説明に示した 浮動小数点 とは数値を指数表現で表す方法である 例えば は指数表現で 3 書く

講習No.8

Microsoft PowerPoint - C言語の復習(配布用).ppt [互換モード]

C プログラミング演習 1( 再 ) 2 講義では C プログラミングの基本を学び 演習では やや実践的なプログラミングを通して学ぶ

プログラミング実習I

スライド 1

ポインタ変数

cp-7. 配列

ゲームエンジンの構成要素

物質工学科 田中晋

Microsoft Word - no103.docx

講習No.12

Microsoft Word - Cプログラミング演習(1)_2012

kiso2-06.key

プログラミング基礎

Microsoft PowerPoint - 説明2_演算と型(C_guide2)【2015新教材対応確認済み】.pptx

プログラミング方法論 II 第 14,15 回 ( 担当 : 鈴木伸夫 ) 問題 17. x 座標と y 座標をメンバに持つ構造体 Point を作成せよ 但し座標 は double 型とする typedef struct{ (a) x; (b) y; } Point; 問題 18. 問題 17 の

Microsoft PowerPoint - 11.pptx

PowerPoint Presentation

PowerPoint プレゼンテーション

Microsoft Word - Cプログラミング演習(3)

ポインタ変数

C 言語第 3 回 2 a と b? 関係演算子 a と b の関係 関係演算子 等しい a==b 等しくない a!=b より大きい a>b 以上 a>=b より小さい a<b 以下 a<=b 状態 真偽 値 条件が満たされた場合 TRUE( 真 ) 1(0 以外 ) 条件が満たされなかった場合 F

Microsoft PowerPoint - CproNt02.ppt [互換モード]

PowerPoint Presentation

演習課題No12

Microsoft PowerPoint - prog03.ppt

3. 標準入出力

fuga scanf("%lf%*c",&fuga); 改行文字を読み捨てる 10 進数の整数 おまじない取り込んだ値を代入する変数 scanf( %d%*c,&hoge); キーボードから取り込め という命令 1: scanf 1 1: int double scanf %d %lf printf

Microsoft PowerPoint - 説柔5_間勊+C_guide5ï¼›2015ã•’2015æŒ°æŁŽæš’å¯¾å¿œç¢ºèª“æ¸‹ã†¿ã•‚.pptx

プログラミングI 第2回 数理物理,総合理学等向け

PowerPoint プレゼンテーション

7 ポインタ (P.61) ポインタを使うと, メモリ上のデータを直接操作することができる. 例えばデータの変更 やコピーなどが簡単にできる. また処理が高速になる. 7.1 ポインタの概念 変数を次のように宣言すると, int num; メモリにその領域が確保される. 仮にその開始のアドレスを 1

講習No.10

Microsoft Word - 03

フローチャートの書き方

<4D F736F F D20438CBE8CEA8D758DC03389F0939A82C282AB2E646F63>

Microsoft PowerPoint - class04.ppt

講習No.9

Microsoft PowerPoint - lec4.ppt

Cプログラミング1(再) 第2回

Microsoft Word - no202.docx

Microsoft PowerPoint - 4.pptx

ポインタ変数

PowerPoint Presentation

第1回 プログラミング演習3 センサーアプリケーション

練習&演習問題

数値計算

情報処理演習 B8クラス

Microsoft PowerPoint - 5Chap15.ppt

Microsoft PowerPoint - 13th.ppt [互換モード]

Microsoft PowerPoint - prog04.ppt

1. 関数 scanf() 関数 printf() は変数の値を画面に表示しますが それに対し関数 scanf() はキーボードで入力した値を変数に代入します この関数を活用することで対話式 ( ユーザーの操作に応じて処理を行う ) プログラムを作ることができるようになります 整数の和

関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include <stdiu.h> #define InFile "data.txt" #define OutFile "surted.txt" #def

演算増幅器

ポインタ変数

問 2 ( 型変換 ) 次のプログラムを実行しても正しい結果が得られない 何が間違いかを指摘し 正しく修正せよ ただし int サイズが 2 バイト long サイズが 4 バイトの処理系での演算を仮定する #include <stdio.h> int main( void ) { int a =

Microsoft Word - no15.docx

Microsoft PowerPoint - 3.ppt [互換モード]

gengo1-8

Microsoft PowerPoint - kougi4.ppt

C 言語の式と文 C 言語の文 ( 関数の呼び出し ) printf("hello, n"); 式 a a+4 a++ a = 7 関数名関数の引数セミコロン 3 < a "hello" printf("hello") 関数の引数は () で囲み, 中に式を書く. 文 ( 式文 ) は

Microsoft PowerPoint - lec10.ppt

C プログラミング 1( 再 ) 第 4 回 講義では C プログラミングの基本を学び 演習では やや実践的なプログラミングを通して学ぶ 1

C 言語第 7 回 掛け算 (multiply number) ìz1 = x1 + iy1 í îz = x + iy 割り算 (devide number) ( )( ) ( ) Þ z z = x + iy x + iy = x x - y y + i y x + x y

Prog1_10th

関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include <stdio.h> #define InFile "data.txt" #define OutFile "sorted.txt" #def

2

Microsoft PowerPoint - kougi9.ppt

4 月 東京都立蔵前工業高等学校平成 30 年度教科 ( 工業 ) 科目 ( プログラミング技術 ) 年間授業計画 教科 :( 工業 ) 科目 :( プログラミング技術 ) 単位数 : 2 単位 対象学年組 :( 第 3 学年電気科 ) 教科担当者 :( 高橋寛 三枝明夫 ) 使用教科書 :( プロ

kiso2-03.key

Microsoft PowerPoint - kougi7.ppt

Microsoft PowerPoint - 12.ppt [互換モード]

FORTRAN( と C) によるプログラミング 5 ファイル入出力 ここではファイルからデータを読みこんだり ファイルにデータを書き出したりするプログラムを作成してみます はじめに テキスト形式で書かれたデータファイルに書かれているデータを読みこんで配列に代入し 標準出力に書き出すプログラムを作り

Microsoft Word - Cプログラミング演習(12)

超初心者用

‚æ2›ñ C„¾„ê‡Ìš|

C言語7

printf("5つの整数を入力して下さい \n"); /* データ入力 */ for( /*** 02 ***/ ){ printf("%dつ目の入力 :",i+1); scanf("%d", /*** 03 ***/ ); sum=dat[0]; /* 合計値の初期設定 */ n_max= 0

訋箊æ©�ã…Šã…�ㇰㅩã…�ㅳㇰ - 第5åłž 浆㇄ㆮ勶御2

1. 入力した文字列を得る 1.1. 関数 scanf() を使う まずは関数 scanf() を使ったプログラムを作ってみましょう 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: #include<stdio.h> #define SIZE 128 main(

2

演習1

Microsoft PowerPoint - prog08.ppt

Microsoft PowerPoint - 4.ppt [互換モード]

Prog1_6th

4-4 while 文 for 文と同様 ある処理を繰り返し実行するためのものだが for 文と違うのは while 文で指定するのは 継続条件のみであるということ for 文で書かれた左のプログラムを while 文で書き換えると右のようになる /* 読込んだ正の整数値までカウントアップ (for

講習No.1

Java講座

ファイル入出力

ファイル入出力

[1] #include<stdio.h> main() { printf("hello, world."); return 0; } (G1) int long int float ± ±

Transcription:

プログラミング演習 バージョン 1 担当教員 : 綴木馴

プログラムの決まりについて学ぶ おすすめする参考書 ザ C 戸川隼人サイエンス社 本日の予定 1. 授業の説明. 2. コンパイラーのインストール.

プログラムの決まりについて学ぶ,P31 /* The most in C */ /* hello.c */ printf("hello,world n");

プログラムの決まり ( コメント ) /* The most in C */ /* hello.c */ printf("hello,world n"); コメントは /*...*/ でくくる

プログラムの決まり ( コメント ) /* The most in C */ /* hello.c */ printf("hello,world n"); まずは決まり文句と思ってください

プログラムの決まり ( 関数 ) /* The most in C */ /* hello.c */ printf("hello,world n"); 関数は必ず ; で終わる 画面に出力する出力関数と呼ぶ n は改行を意味する 出力させたい内容を " でくくる

プログラミングの決まり ( 行の概念は無い ) /* The most in C */ /* hello.c */ printf("hello,world n"); /* The most in C */ /* hello.c */ printf("hello,world n");

課題 P35,4.3, 4.4, 4.5

今日のプログラム ( 入出力の関数 )P36 int data; printf("input an integer :"); scanf("%d",&data); printf("the interger is %d n",data);

変数の取り扱い int data; printf("input an integer :"); scanf("%d",&data); printf("the interger is %d n",data); data という整数型の変数を宣言する ( 変数を使えるようにする ) 整数型文字型実数型 int 1,2,100,-4 など char a,b,c など float 1.2, 100, 34.1 など

出力関数の取り扱い & を忘れるな ( 今は決まり文句と 思っておく ) int data; printf("input an integer :"); scanf("%d",&data); printf("the interger is %d n",data); 入力関数と呼ぶ キーボードから %d に入力された整数を data に保存する 整数型 %d 文字型 %c 実数型 %f 10 進数 %d 8 進数 %o 16 進数 %x

出力関数の取り扱い int data; printf("input an integer :"); scanf("%d",&data); printf("the interger is %d n",data); data の値を画面に出力する

P43 5.1,5.2,5.3 課題

第 6 章簡単な計算 p44 double r, s; printf( radius = "); scanf( %lf",&r); s = 3.14 * r * r printf("the area is %f n",s); 新しいポイント double %lf * ( 掛け算の記号つまり )

第 6 章簡単な計算 double r, s; printf( radius = "); scanf( %lf",&r); s = 3.14 * r * r printf("the area is %f n",s); 新しいポイント double について

倍精度実数型 floatよりも倍の精度 ( 例えば : 小数点の 桁数が多い ) の値が使える double r, s; printf( radius = "); scanf( %lf",&r); s = 3.14 * r * r printf("the area is %f n",s); 知識の追加 整数型 int 1,2,100,-4 など今までの知識 : 文字型 char a,b,c など実数型 float 1.2, 100, 34.1 など新しい知識 : 倍精度実数型 double 1.2, 100, 34.1 など

第 6 章簡単な計算 double r, s; printf( radius = "); scanf( %lf",&r); s = 3.14 * r * r printf("the area is %f n",s); 新しいポイント double %lf について

倍精度実数型変数への入力 double r, s; printf( radius = "); scanf( %lf",&r); s = 3.14 * r * r printf("the area is %f n",s); 知識の追加 今までの知識 : 整数型 %d 文字型 %c 実数型 %f 10 進数 %d 8 進数 %o 16 進数 %x 新しい知識 : 倍精度実数型 %lf

倍精度実数型変数への入力 & を忘れるな ( 今は決まり文句と 思っておく ) double r, s; printf( radius = "); scanf( %lf",&r); s = 3.14 * r * r printf("the area is %f n",s); 知識の追加 キーボードから %lf に入力された倍精度実数を r に保存する 新しい知識 : 倍精度実数型 %lf

四則演算 double r, s; printf( radius = "); scanf( %lf",&r); s = 3.14 * r * r printf("the area is %f n",s); 知識の追加 * 掛け算 / 割り算 + 足し算 - 引き算 % わり算の余り

今日の注意 double r, s; printf( radius = "); scanf( %lf",&r); s = 3.14 * r * r printf("the area is %f n",s); s は倍精度実数型で宣言されているが普通の実数型で出力されている

課題 P54 6.1, 6.2, 6.3

今日の目的 : 条件分岐 (if 文 )P67 #include <math.h> double a, b, c, d, rd, x1, x2; printf(" a= "); scanf("lf",&a); printf(" b= "); scanf("lf",&b); printf(" c= "); scanf("lf",&c); d = b * b - 4 * a * c; if(d >= 0) rd = sqrt(d); x1 = (-b - rd) / (2 * a); x2 = (-b + rd) / (2 * a); printf("solution_1 = %f n", x1); printf("solution_2 = %f n", x2); else printf("no real solution n");

今日の目的 : 条件分岐 (if 文 ) #include <math.h> double a, b, c, d, rd, x1, x2; printf(" a= "); scanf("lf",&a); printf(" b= "); scanf("lf",&b); printf(" c= "); scanf("lf",&c); d = b * b - 4 * a * c; if(d >= 0) rd = sqrt(d); x1 = (-b - rd) / (2 * a); x2 = (-b + rd) / (2 * a); printf("solution_1 = %f n", x1); printf("solution_2 = %f n", x2); else printf("no real solution n"); 新しい箇所 #include <math.h> sqrt(d) if else

平方根を取る関数 :sqrt() #include <math.h> double a, b, c, d, rd, x1, x2; printf(" a= "); scanf("lf",&a); printf(" b= "); scanf("lf",&b); printf(" c= "); scanf("lf",&c); d = b * b - 4 * a * c; if(d >= 0) rd = sqrt(d); x1 = (-b - rd) / (2 * a); x2 = (-b + rd) / (2 * a); printf("solution_1 = %f n", x1); printf("solution_2 = %f n", x2); else printf("no real solution n"); sqrt を使えるようにするための決まり文句 かっこ内 () のルート ( ) を計算する

今日の目的 : 条件分岐 (if 文 ) #include <math.h> double a, b, c, d, rd, x1, x2; printf(" a= "); scanf("lf",&a); printf(" b= "); scanf("lf",&b); printf(" c= "); scanf("lf",&c); d = b * b - 4 * a * c; if(d >= 0) rd = sqrt(d); x1 = (-b - rd) / (2 * a); x2 = (-b + rd) / (2 * a); printf("solution_1 = %f n", x1); printf("solution_2 = %f n", x2); else printf("no real solution n"); 新しい箇所 if( 条件 ) ( 条件 ) を満たすならばすぐ下の 内を実行 else ( 条件 ) を満たさないならばすぐ下の 内を実行 1 行の時のみ 内を実行できる

今日の目的 : 条件分岐 (if 文 ) #include <math.h> double a, b, c, d, rd, x1, x2; printf(" a= "); scanf("lf",&a); printf(" b= "); scanf("lf",&b); printf(" c= "); scanf("lf",&c); d = b * b - 4 * a * c; if(d >= 0) rd = sqrt(d); x1 = (-b - rd) / (2 * a); x2 = (-b + rd) / (2 * a); printf("solution_1 = %f n", x1); printf("solution_2 = %f n", x2); else printf("no real solution n"); 新しい箇所 if( 条件 ) 条件式の定義 a==b a=bのとき a!=b a bのとき a > b a>b のとき a<b a<bのとき a>=b a bのとき a<=b a bのとき

課題 P72 8.1, 8.2, 8.3

今日の目的 : 繰り返し (while 文,P81) #include <math.h> #define EPS 1e-5 double a, old_x, new_x; int i; printf(" a= "); scanf("%lf, &a); 新しい箇所 #define while i++; new_x = a; i = 0; while(i < 100) old_x = new_x; new_x = (old_x + a / old_x) / 2; printf("x = %f n", new_x); if(fabs(new_x - old_x)/old_x <EPS) break; i++; break; fabs

今日の目的 : 繰り返し (while 文,P81) #include <math.h> #define EPS 1e-5 double a, old_x, new_x; int i; EPSを 10-5 と定義する printf(" a= "); scanf("%lf, &a); new_x = a; i = 0; while(i < 100) old_x = new_x; new_x = (old_x + a / old_x) / 2; printf("x = %f n", new_x); if(fabs(new_x - old_x)/old_x <EPS) break; i++;

今日の目的 : 繰り返し (while 文,P81) #include <math.h> #define EPS 1e-5 double a, old_x, new_x; int i; printf(" a= "); scanf("%lf, &a); while( 条件 ) ( 条件 ) が成立している場合は 内を繰り返す new_x = a; i = 0; while(i < 100) old_x = new_x; new_x = (old_x + a / old_x) / 2; printf("x = %f n", new_x); if(fabs(new_x - old_x)/old_x <EPS) break; i++;

今日の目的 : 繰り返し (while 文,P81) #include <math.h> #define EPS 1e-5 double a, old_x, new_x; int i; fabs が使えるようにする printf(" a= "); scanf("%lf, &a); new_x = a; i = 0; while(i < 100) old_x = new_x; new_x = (old_x + a / old_x) / 2; printf("x = %f n", new_x); if(fabs(new_x - old_x)/old_x <EPS) break; i++; ( ) 内の絶対値をとる while 文から抜け出す.

今日の目的 : 繰り返し (while 文,P81) #include <math.h> #define EPS 1e-5 double a, old_x, new_x; int i; printf(" a= "); scanf("%lf, &a); new_x = a; i = 0; while(i < 100) old_x = new_x; new_x = (old_x + a / old_x) / 2; printf("x = %f n", new_x); if(fabs(new_x - old_x)/old_x <EPS) break; i++; i++; i に 1 を足す i=i+1; または ++i; と書いても良い

今日の目的 : 繰り返し 2(while 文,P82) double ave, sum=0; int data, num=0; printf("data = "); while(1) scanf("%d", &data); if(data= = 12345)break; sum += data; num++; printf("data = ") ; if(num = = 0) printf("can't calculate the average n"); else ave = sum / num; printf("the average of %d data is %f n, num, ave); 新しい箇所 +=

課題 P84 9.1, 9.2, 9.3

今日の目的 : 繰り返し 2(while 文,P82) double ave, sum=0; int data, num=0; printf("data = "); while(1) scanf("%d", &data); if(data= = 12345)break; sum += data; num++; printf("data = ") ; if(num = = 0) printf("can't calculate the average n"); else ave = sum / num; printf("the average of %d data is %f n, num, ave); 新しい箇所 += sum += data; は sum = sum +data; と同じ.

課題 P84, 9.4, 9.5, 9.6

今日の目的 : 繰り返し (do, while 文,P97) #include <time.h> int d, x; unsigned seed; printf("input an integer to seed ="); scanf("%d", &seed); srand(seed); x = rand(); x %= 100; printf("data = ";) do printf("hit my number(0-99)"); scanf("%d", &d); if(x > d) printf("greater than %d n", d); else if(x < d) printf( less than %d n", d); while(x!= d); printf("congratulations! n"); 新しい箇所 unsigned srand() rand() do, while

今日の目的 : 繰り返し (do, while 文,P97) #include <time.h> int d, x; unsigned seed; printf("input an integer to seed ="); scanf("%d", &seed); srand(seed); x = rand(); x %= 100; do printf("hit my number(0-99)"); scanf("%d", &d); if(x > d) printf("greater than %d n", d); else if(x < d) printf( less than %d n", d); while(x!= d); unsigned 符号なしの正数つまり正の整数のみの場合に使用 printf("congratulations! n");

今日の目的 : 繰り返し (do, while 文,P97) #include <time.h> int d, x; unsigned seed; printf("input an integer to seed ="); scanf("%d", &seed); srand(seed); x = rand(); x %= 100; do printf("hit my number(0-99)"); scanf("%d", &d); if(x > d) printf("greater than %d n", d); else if(x < d) printf( less than %d n", d); while(x!= d); srand() 乱数の種を与える rand() 乱数を発生させる printf("congratulations! n");

今日の目的 : 繰り返し (do, while 文,P97) #include <time.h> int d, x; unsigned seed; printf("input an integer to seed ="); scanf("%d", &seed); srand(seed); x = rand(); x %= 100; do printf("hit my number(0-99)"); scanf("%d", &d); if(x > d) printf("greater than %d n", d); else if(x < d) printf( less than %d n", d); while(x!= d); do, while while( 条件 ) 条件を満たしている間 内を繰り返す. printf("congratulations! n");

課題 P98,10.2,10.3,10.4

for 文 (P89) #include<math.h> #define EPS 1e-5 double a, old_x, new_x; int i; printf(" a ="); scanf("%lf", &a); 新しいポイント for( 初期設定 ; 反復条件 ; 変更処理 ) new_x = a; for(i = 0; i < 100; i++) old_x = new_x ; new_x = (old_x + a / old_x) / 2; printf("x = %f n, new_x); if(fabs(new_x - old_x)/old_x < EPS) break;

for 文 ( P89 ) #include<math.h> #define EPS 1e-5 double a, old_x, new_x; int i; printf(" a ="); scanf("%lf", &a); 新しいポイント for( 初期設定 ; 反復条件 ; 変更処理 ) new_x = a; for(i = 0; i < 100; i++) old_x = new_x ; new_x = (old_x + a / old_x) / 2; printf("x = %f n, new_x); if(fabs(new_x - old_x)/old_x < EPS) break;

for 文 ( P89 ) #include<math.h> #define EPS 1e-5 double a, old_x, new_x; int i; printf(" a ="); scanf("%lf", &a); new_x = a; for(i = 0; i < 100; i++) old_x = new_x ; new_x = (old_x + a / old_x) / 2; printf("x = %f n, new_x); if(fabs(new_x - old_x)/old_x < EPS) break; 新しいポイント for( 初期設定 ; 反復条件 ; 変更処理 ) i=0 と初期設定する

for 文 ( P89 ) #include<math.h> #define EPS 1e-5 double a, old_x, new_x; int i; printf(" a ="); scanf("%lf", &a); new_x = a; for(i = 0; i < 100; i++) old_x = new_x ; new_x = (old_x + a / old_x) / 2; printf("x = %f n, new_x); if(fabs(new_x - old_x)/old_x < EPS) break; 新しいポイント for( 初期設定 ; 反復条件 ; 変更処理 ) i が 100 より小さい間 内を繰り返す

for 文 ( P89 ) #include<math.h> #define EPS 1e-5 double a, old_x, new_x; int i; printf(" a ="); scanf("%lf", &a); 新しいポイント for( 初期設定 ; 反復条件 ; 変更処理 ) i に 1 を加える new_x = a; for(i = 0; i < 100; i++) old_x = new_x ; new_x = (old_x + a / old_x) / 2; printf("x = %f n, new_x); if(fabs(new_x - old_x)/old_x < EPS) break;

課題 1.1 から 1000 までの和を for 文を使って求めよ. 2.P98,10.1(cf p82),10.5

文字型の配列 ( 文字列 ) char a[100]; int i = 0; print(" 何か文字列を入力して下さい."); scanf("%s", a); while(a[i]!= 0) printf("a[%d] = %c n", i, a[i]); i++; 新しいポイント a[100] %s 文字列を入力し, 先頭から一字ずつ取り出して表示するプログラム

文字型の配列 ( 文字列 ) char a[100]; int i = 0; printf(" 何か文字列を入力して下さい."); scanf("%s", a); while(a[i]!= 0) printf("a[%d] = %c n", i, a[i]); i++; 新しいポイント a[100] 100 個の文字型配列を確保 例 :abcdefg と入力した場合 a b c d e f g 終 a[0] a[3] a[5] a[8]=0

文字型の配列 ( 文字列 ) char a[100]; int i = 0; print(" 何か文字列を入力して下さい."); scanf("%s", a); while(a[i]!= 0) printf("a[%d] = %c n", i, a[i]); i++; 新しいポイント 文字列型 %s 文字型配列 a[100] に文字列をキーボードから入力 復習 : 整数型 %d 文字型 %c 実数型 %f 10 進数 %d 8 進数 %o 16 進数 %x

文字型の配列 ( 文字列 ) の課題 1. 例題を do while 文で書き直せ. 2. 例題を for 文で書き直せ. 3.abcde と入力し,a[0]~a[6] を整数で表示してみよ. 4. 入力された文字列を一発表示せよ. ヒント :printf("%s", a);

文字列のコピー int i; char a[100], b[100]; for(i = 0; i<100; i++) b[i] = 0; printf(" 文字列を入力して下さい "); scanf("%s", a); for(i = 0; a[i]!= 0; i++) b[i] = a[i]; printf(" 文字列 b を表示します %s n", b); 新しいポイント 特になし

文字列のコピー ( 課題 ) 1. 例題を do while 文で書き直せ. 2. 例題を while 文で書き直せ. 3.10 個の配列を用意し,0~99 までの整数を 10 個ランダムに生成して配列に代入し表示せよ.

2 次元配列 int i; char a[2][100]; for(i = 0; i<100; i++) a[1][i] = 0; printf(" 文字列を入力して下さい "); scanf("%s", a[0]); for(i = 0; a[0][i]!= 0; i++) a[1][i] = a[0][i]; printf(" 文字列 a[1] を表示します %s n", a[1]);

2 次元配列 int i; char a[2][100]; for(i = 0; i<100; i++) a[1][i] = 0; printf(" 文字列を入力して下さい "); scanf("%s", a[0]); for(i = 0; a[0][i]!= 0; i++) a[1][i] = a[0][i]; printf(" 文字列 a[1] を表示します %s n", a[1]); 新しいポイント a[2][100];

2 次元配列 int i; char a[2][100]; for(i = 0; i<100; i++) a[1][i] = 0; printf(" 文字列を入力して下さい "); scanf("%s", a[0]); for(i = 0; a[0][i]!= 0; i++) a[1][i] = a[0][i]; printf(" 文字列 a[1] を表示します %s n", a[1]); 新しいポイント a[2][100]; a[0][0], a[0][1], a[0][2],, a[0][98], a[0][99] a[1][0], a[1][1], a[1][2],, a[1][98], a[1][99]

2 次元配列 ( 課題 ) 1. 例題を do while 文で書き直せ. 2. 例題を while 文で書き直せ. 3.10 個の配列を用意し,0~99 までの整数を 10 個ランダムに生成してその配列に代入し, その中から最大値を求めよ.

2 次元配列 ( 整数型 ) int i; int a[2][100]; for(i = 0; i<100; i++) printf(" 整数を入力せよ (0で終了)"); scanf("%d", &a[0][i]); if(a[0][i]= =0) break; for(i = 0; a[0][i]!= 0; i++) a[1][i] = a[0][i]; printf(" 整数 a[1][%d] %d n", i, a[1][i]);

2 次元配列 ( 課題 ) 1.0~99 までの整数を 10 個ランダムに生成し, 大きい順に並び替えるプログラムを作成せよ.

ヒント 1.3 つの配列を用意する. 2.1 つ目の配列には乱数を代入. 3.2 つ目の配列には 0 を代入. 4. 配列の中から最大値を求める. 5. 求めた最大値を 3 つ目の配列に代入し, 対応する 2 つ目の配列に 1 を代入する. 6.2 つ目の配列で 1 のついていないものから最大値を求める. 7.5 に戻る. 54 23 56 11 6 74 45 88 59 21 17 95 46 85 47 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 54 23 56 11 6 74 45 88 59 21 17 95 46 85 47 4 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 95 54 23 56 11 6 74 45 88 59 21 17 95 46 85 47 4 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 95 88