新・明解C言語で学ぶアルゴリズムとデータ構造

Size: px
Start display at page:

Download "新・明解C言語で学ぶアルゴリズムとデータ構造"

Transcription

1 第 1 章 基本的 1 n

2 三値 最大値 algorithm List 1-1 a, b, c max /* */ #include <stdio.h> int main(void) { int a, b, c; int max; /* */ List 1-1 printf("\n"); printf("a"); scanf("%d", &a); printf("b"); scanf("%d", &b); printf("c"); scanf("%d", &c); max = a; if (b > max) max = b; if (c > max) max = c; printf("%d\n", max); return 0; a, b, c max chap01/max3.c 実行例 a1 Ÿ b3 Ÿ c2 Ÿ 3 a, b, c max max a b max max b c max max c concatination if ( ) if selection

3 15 + > operator operandb max b > max > b max unary operator a++ binary operator a < b ternary operator a? b : c 1-1 Column 1-1 演算子 / 式 評価 expression x = n x n int x, n, 135, n + 135, x = n x n x = n assignment expression void evaluation Fig.1C-1 int n 52 n 52 n, 135, n , 135, 187 int int 52 int 135 n int 187 Fig.1C-1 int + int

4 161 flowchart Fig.1-1 p.24 max = a; if (b > max) max = b; if (c > max) max = c; a max b > max Yes b > c > a No b max c > max Yes No c max Fig b > max c > max b > max c > max 1 if while ( ) if a max a max List 1-2p.18 int max = a; max = a;

5 17 a, b, c 1, 3, 2 a, b, c 1, 2, 3 3, 2, 1 5, 5, 5 1, 3, 1 Fig.1-2 max = a; if (b > max) max = b; a a = 1 b = 3 c = 2 max 1 3 b a = 1 b = 2 c = 3 max 1 2 c a = 3 b = 2 c = 1 max 3 3 d a = 5 b = 5 c = 5 max 5 5 e a = 1 b = 3 c = 1 max if (c > max) max = c; Fig.1-2 max a, b, c 6, 10, 7-10, 100, 10 b c a Column 1-2 関係演算子 等価演算子 <, <=, >, >= ==,!= int 1 int 0 Fig.1C-2 5 > 3 int 1 a 5 == 3 int 0 bc int int a int > int b int == int c double < double 5 > 3 5 == < 3.2 int 1 int 0 int 0 Fig.1C-2

6 List 1-2 List 1-2 /* */ #include <stdio.h> /*--- a, b, c ---*/ int max3(int a, int b, int c) { int max = a; /* */ if (b > max) max = b; if (c > max) max = c; return max; int main(void) { printf("max3(%d,%d,%d) = %d\n", 3, 2, 1, max3(3, 2, 1)); /* [A] abc */ printf("max3(%d,%d,%d) = %d\n", 3, 2, 2, max3(3, 2, 2)); /* [B] abc */ printf("max3(%d,%d,%d) = %d\n", 3, 1, 2, max3(3, 1, 2)); /* [C] acb */ printf("max3(%d,%d,%d) = %d\n", 3, 2, 3, max3(3, 2, 3)); /* [D] acb */ printf("max3(%d,%d,%d) = %d\n", 2, 1, 3, max3(2, 1, 3)); /* [E] cab */ printf("max3(%d,%d,%d) = %d\n", 3, 3, 2, max3(3, 3, 2)); /* [F] abc */ printf("max3(%d,%d,%d) = %d\n", 3, 3, 3, max3(3, 3, 3)); /* [G] abc */ printf("max3(%d,%d,%d) = %d\n", 2, 2, 3, max3(2, 2, 3)); /* [H] cab */ printf("max3(%d,%d,%d) = %d\n", 2, 3, 1, max3(2, 3, 1)); /* [I] bac */ printf("max3(%d,%d,%d) = %d\n", 2, 3, 2, max3(2, 3, 2)); /* [J] bac */ printf("max3(%d,%d,%d) = %d\n", 1, 3, 2, max3(1, 3, 2)); /* [K] bca */ printf("max3(%d,%d,%d) = %d\n", 2, 3, 3, max3(2, 3, 3)); /* [L] bca */ printf("max3(%d,%d,%d) = %d\n", 1, 2, 3, max3(1, 2, 3)); /* [M] cba */ return 0; chap01/max3comb.c 実行結果 max3(3,2,1) = 3 max3(3,2,2) = 3 max3(3,1,2) = 3 max3(3,2,3) = 3 max3(2,3,2) = 3 max3(1,3,2) = 3 max3(2,3,3) = 3 max3(1,2,3) = 3 [A], [B],, [M] Fig.1C-4p.20A, ʙ,, M function max3 int a, b, c int main max3 Column Column 1-4p.20

7 19 JISJapanese Industrial Standards max4 int max4(int a, int b, int c, int d); main 1-2 min3 int min3(int a, int b, int c); 1-3 min4 int min4(int a, int b, int c, int d); p.3 Column 1-3 関数 返却値 関数呼出 式 評価 return max3 int max 4 4 max(3, 2, 1) Fig.1C-3 max(3, 2, 1) int 3 void max(3, 2, 1) int 3 Fig.1C-3

8 Fig.1C-4 decision tree a b A a b c Yes b c ʙ No a b c C b c a c b a c D a c E a c b c a b a b F a b c b c ɢ b c ʜ a b c a b c a b ɪ b a c a c J b a c K a c b c a b c ʟ b c M b c a c b a Column 1-4 三値 大小関係 中央値 Fig.1C-4 a, b, c a, b, c List 1-2 A, ʙ,, M 13 List 1C-1 return A, ʙ,, MFig.1C-4

9 21List 1C-1 /* */ #include <stdio.h> /*--- a, b, c ---*/ int med3(int a, int b, int c) { if (a >= b) if (b >= c) return b; A ʙ F ɢ else if (a <= c) return a; D E ʜ else return c; C else if (a > c) return a; ɪ else if (b > c) return c; J K else return b; ʟ M int main(void) { int a, b, c; chap01/med3.c 実行例 a1 Ÿ b3 Ÿ c2 Ÿ printf("\n"); printf("a"); scanf("%d", &a); printf("b"); scanf("%d", &b); printf("c"); scanf("%d", &c); printf("%d\n", med3(a, b, c)); return 0; List 1-2 List 1C List 1C-1 med3 int med3(int a, int b, int c) { if ((b >= a && c <= a) (b <= a && c >= a)) return a; else if ((a > b && c < b) (a < b && c > b)) return b; return c;

10 221 条件判定 分岐 List 1-3 /* */ #include <stdio.h> int main(void) { int n; List 1-3 printf(""); scanf("%d", &n); if (n > 0) printf("\n"); else if (n < 0) printf("\n"); else printf("\n"); return 0; ㆒ ㆓ 叅 chap01/sign.c 実行例㆒ 5 Ÿ 実行例㆓ -5 Ÿ 実行例叅 0 Ÿ Fig.1-3 n ㆒ ㆓ 0 叅 "chap01/if123a.c" ㆒,, n No Yes n No ㆒㆓ Yes 叅 Fig.1-3 n

11 23if (n == 1) printf("\n"); else if (n == 2) printf("\n"); else if (n == 3) printf("\n"); n 1 ㆒ 2 ㆓ 3 叅 ㆒ ㆓ 叅 if if () else if () else List 1-3 "chap01/if123b.c" n Ÿ 叅 if "chap01/if123c.c" 1-1 if (n == 1) printf("\n"); ㆒ else if (n == 2) printf("\n"); ㆓ else if (n == 3) printf("\n"); 叅 else ; /* */ 4 4 List 1-3 if Column 1-5 条件演算子? : conditional operator conditional expressionfig.1c-5 min = a < b? a : b; min a b a b 1? 2 : 3 1 a true 2 b false 3 a a29b52 a < b? a : b b a31b15 a < b? a : b int 29 int 15 Fig.1C-5

12 241 ( 流 図 ) 記号 flowchart 流 図 (program flowchart) (data) Fig.1-4 処理 (process) Fig.1-5 定義 処理 (predefined process) Fig.1-6 Fig.1-4 Fig.1-5 判断 (decision) Fig.1-7 Fig.1-6 Fig.1-7

13 25 端 (loop limit) Fig.1-8 Fig.1-9 a Fig.1-8 b 1-1 i a, b, c i : 1, 1, n i : 1, 1, n Fig.1-9 ab i 1 n 1 n 1, 1, n 1, 2,, n 線 (line) Fig.1-10 Fig.1-10 端子 (terminator) Fig.1-11 Fig.1-11

14 繰返 1 n 整数 和 求 1 n n n n List 1-4 Fig.1-12 /* 1, 2,, nwhile*/ #include <stdio.h> int main(void) { int i, n; int sum; /* */ puts("1n"); printf("n"); scanf("%d", &n); sum = 0; i = 1; List 1-4 while (i <= n) { /* in */ sum += i; /* sumi */ i++; /* i */ printf("1%d%d\n", n, sum); return 0; ㆒ ㆓ chap01/sum_while.c 実行例 1n n5 Ÿ 1515 while 文 繰返 repetitionloop while 4 while 0 while ( )

15 27 sum ㆒ 1 i ㆓ i n Yes sum + i sum i + 1 i No i sum i sum Fig n ㆒ ㆓ ㆒ sum 0 i 1 ㆓ i n i n += ++ i n i <= n i sum i sum ㆒ 1 0 i sum i i 5 sum i 5 4 i n while i n n List 1-4 while i n + 1 i

16 281 for 文 繰返 while for 1 n for List 1-5 List 1-5 /* 1, 2,, nfor*/ #include <stdio.h> int main(void) { int i, n; int sum; /* */ puts("1n"); printf("n"); scanf("%d", &n); sum = 0; for (i = 1; i <= n; i++) { /* i = 1, 2,, n */ sum += i; /* sumi */ printf("1%d%d\n", n, sum); chap01/sum_for.c 実行例 1n n5 Ÿ 1515 return 0; Fig.1-13 loop limit i 1, 2, 3, 1 n 1 sum += i; sum i : 1, 1, n sum + i sum i 1 n Fig n

17 29for for ( 1 ; 2 ; 3 ) for while /*--- for ---*/ /*--- while ---*/ for ( 1 ; 2 ; 3 ) 1 ; while ( 2 ) { 3 ; for List 1-5 n = (1 + 10) * 5 1 n 1-9 a, b int sumof(int a, int b); a b a 3 b 5 12 a 6 b 4 15 Column 1-6 非 真 偽 Column 1-2p.17 int 1 int if (a) printf("abc"); a ABC

18 301 正 値 読込 List 1-5 n n List 1-6 /* 1, 2,, ndon*/ #include <stdio.h> int main(void) { int i, n; int sum; /* */ List 1-6 puts("1n"); do { printf("n"); n scanf("%d", &n); while (n <= 0); sum = 0; for (i = 1; i <= n; i++) { /* i = 1, 2,, n */ sum += i; /* sumi */ printf("1%d%d\n", n, sum); return 0; chap01/sum_for_pos.c 実行例 1n n-6 Ÿ n0 Ÿ n10 Ÿ n 0 n do do while ( ); while for ; do 4 ( ) Fig.1-14

19 31Yes n n n n 1-2 a b No n n Fig.1-14 ab ba do n 0 do n 前判定繰返 後判定繰返 相違点 while for 0 do 1-10 a, b b - a b a b a6 Ÿ b6 Ÿ a b8 Ÿ b - a

20 321 構造化 structured programming Column 1-7 論理演算 法則 p.30list 1-6 List 1C-2 List 1C-2 /* 1099 */ #include <stdio.h> int main(void) { int no; chap01/dbl_digits.c 実行例 5 Ÿ 105 Ÿ 57 Ÿ no57 printf("\n"); do { printf(""); scanf("%d", &no); while (no < 10 no > 99); printf("no%d\n", no); return 0; do List 1-6 no && Fig.1C-6 a x y x && y b x y x y Fig.1C-6

21 33 no 5 no < 10 1 no > 99 no < 10 no > 99 1 x y 0 x y 1 1 && short circuit evaluation 1-2! !(no >= 10 && no <= 99) 4 4 De Morgan's laws x && y!(!x!y) x y!(!x &&!y) no < 10 no > 99!(no >= 10 && no <= 99) Fig.1C-7 do { /* no */ while (no < 10 no > 99); do { /* no */ while (!(no >= 10 && no <= 99)); ㆒ ㆓ Yes! Yes No No Fig.1C-7

22 341 多重 九九 表 List 1-7 List 1-7 /* */ #include <stdio.h> int main(void) { int i, j; printf(" \n"); for (i = 1; i <= 9; i++) { for (j = 1; j <= 9; j++) printf("%3d", i * j); putchar('\n'); return 0; chap01/multi99table.c 実行結果 Fig.1-15 i j for 4 i for 4 j i j i 1 j * j i 2 j * j i 3 j * j i 9 j * j

23 35 i : 1, 1, 9 i j i j j : 1, 1, 9 i * j Fig ' ' '-' '+' * 1-15 * 4 Ÿ **** **** **** **** 3 Ÿ 7 Ÿ ******* ******* *******

24 361 直角二等辺三角形 表示 List 1-8 List 1-8 do n /* */ #include <stdio.h> int main(void) { int i, j, n; do { printf(""); scanf("%d", &n); while (n <= 0); for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) putchar('*'); putchar('\n'); return 0; chap01/trianglelb.c 実行例 5 Ÿ * ** *** **** ***** Fig.1-16 i j n 5 for 4 i 1 n 5 4 for 4 j 1 i 4 i 1 j 1 1 * * i 2 j 1 2 * ** i 3 j 1 3 * *** i 4 j 1 4 * **** i 5 j 1 5 * ***** 1 n i i '*' n n '*'

25 37 i : 1, 1, n i j n 5 i j j : 1, 1, i * Fig void trianglelb(int n); /* */ void trianglelu(int n); /* */ void triangleru(int n); /* */ void trianglerb(int n); /* */ 1-17 n 4 void spira(int n); i (i - 1) * '*' n (n - 1) * '*' * *** ***** ******* 1-18 n void nrpira(int n); i i %

26 381 章末問題 p 処理条件処理条件 処理 条件 処理 処理 処理 while 条件 処理 条件 条件 処理 処理 条件 処理 処理 処理 条件 処理 処理 処理 処理

27 a データ ( 入出力 ) b 内部記憶 e 判断 f 定義済み処理 ( サブルーチン ) 1 c 処理 g ループ端 ( 繰返し ) d 並列処理 h 結合子 i 端子 a a NN 11 2 N x a 開始 0 x 1 i a No x + i x i + 1 i Yes 終了 i N i N i N x N

新・明解Javaで学ぶアルゴリズムとデータ構造

新・明解Javaで学ぶアルゴリズムとデータ構造 第 1 章 基本的 1 n 21 1-1 三値 最大値 algorithm List 1-1 a, b, c max // import java.util.scanner; class Max3 { public static void main(string[] args) { Scanner stdin = new Scanner(System.in); List 1-1 System.out.println("");

More information

C言語によるアルゴリズムとデータ構造

C言語によるアルゴリズムとデータ構造 Algorithms and Data Structures in C 4 algorithm List - /* */ #include List - int main(void) { int a, b, c; int max; /* */ Ÿ 3Ÿ 2Ÿ 3 printf(""); printf(""); printf(""); scanf("%d", &a); scanf("%d",

More information

明解Javaによるアルゴリズムとデータ構造

明解Javaによるアルゴリズムとデータ構造 21 algorithm List 1-1 a, b, c max Scanner Column 1-1 List 1-1 // import java.util.scanner; class Max3 { public static void main(string[] args) { Scanner stdin = new Scanner(System.in); Chap01/Max3.java

More information

Javaによるアルゴリズムとデータ構造

Javaによるアルゴリズムとデータ構造 1 algorithm List 1-1 a, b, c List 1-1 // import java.util.scanner; class Max3 { public static void main(string[] args) { Scanner stdin = new Scanner(System.in); int a, b, c; int max; // Chap01/Max3.java

More information

Microsoft PowerPoint - 説明3_if文switch文(C_guide3)【2015新教材対応確認済み】.pptx

Microsoft PowerPoint - 説明3_if文switch文(C_guide3)【2015新教材対応確認済み】.pptx 情報ネットワーク導入ユニット Ⅰ C 言語 if 文 switch 文 3 章 : プログラムの流れの分岐 if 文 if( 条件 ) 条件が成立すれば実行 if( 条件 ) ~ else 場合分け ( 成立, 不成立 ) if( 条件 A) ~ else if( 条件 B) ~ else if( 条件 C) ~ else 場合分け ( 複数の条件での場合分け ) 等価演算子 : == ( 等しい

More information

新版明解C言語入門編

新版明解C言語入門編 175cm 60kg ( ) 175cm 175.3cm 175.869758 cm 175cm 60kg p.177 18-1 vx - vy vx vy List -1 List -1 int vx, vy; puts(""); printf(" vx "); scanf("%d", &vx); printf(" vy "); scanf("%d", &vy); printf("vx + vy

More information

プログラミング基礎

プログラミング基礎 C プログラミング Ⅰ 条件分岐 if~else if~else 文,switch 文 条件分岐 if~else if~else 文 if~else if~else 文 複数の条件で処理を分ける if~else if~else 文の書式 if( 条件式 1){ 文 1-1; 文 1-2; else if( 条件式 2){ 文 2-1; 文 2-2; else { 文 3-1; 文 3-2; 真条件式

More information

新・明解C言語 実践編

新・明解C言語 実践編 第 1 章 見 21 1-1 見えないエラー 見 List 1-1 "max2x1.h" a, b max2 List 1-1 chap01/max2x1.h max2 "max2x1.h" #define max2(a, b) ((a) > (b)? (a) : (b)) max2 List 1-2 List 1-2 chap01/max2x1test.c max2 #include

More information

新版 明解C++入門編

新版 明解C++入門編 第 1 章画面 出力 入力 C++ C++ C++ C++ C++ C++ C++ C++ #include using C++ C++ C++ main C++ C++ C++ int double char C++ C++ C++ string C++ C++ C++ 21 1-1 C++ 歴史 C++ C++ 歴史 CC with classes Fig.1-1 C C++ Simula 67

More information

P05.ppt

P05.ppt 2 1 list0415.c forfor #include int i, j; for (i = 1; i

More information

プログラミング基礎

プログラミング基礎 C プログラミング Ⅰ 条件分岐 : if 文, if~else 文 条件分岐 条件分岐とは ある条件が成立したときとしないときで処理の内容を変更する場合に応じた, 複雑な処理を行うことができる 条件分岐 yes 成績が良かったか? no ご褒美に何か買ってもらう お小遣いが減らされる C 言語では,if 文,if~else 文,if~else if~else 文,switch 文で条件分岐の処理を実現できる

More information

‚æ4›ñ

‚æ4›ñ ( ) ( ) ( ) A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 (OUS) 9 26 1 / 28 ( ) ( ) ( ) A B C D Z a b c d z 0 1 2 9 (OUS) 9

More information

C のコード例 (Z80 と同機能 ) int main(void) { int i,sum=0; for (i=1; i<=10; i++) sum=sum + i; printf ("sum=%d n",sum); 2

C のコード例 (Z80 と同機能 ) int main(void) { int i,sum=0; for (i=1; i<=10; i++) sum=sum + i; printf (sum=%d n,sum); 2 アセンブラ (Z80) の例 ORG 100H LD B,10 SUB A LOOP: ADD A,B DEC B JR NZ,LOOP LD (SUM),A HALT ORG 200H SUM: DEFS 1 END 1 C のコード例 (Z80 と同機能 ) int main(void) { int i,sum=0; for (i=1; i

More information

Microsoft PowerPoint - class04.ppt

Microsoft PowerPoint - class04.ppt フローチャート フローチャートとは プログラムの処理の流れを整理し 図的に順序立てて描いたもの 流れ図流れ図ともいう 例 : 始め 半径 R 端子 : 開始 終了 停止などを示す 手操作入力 : キーボードなどから手で操作して入力することを示す 面積 S πr 2 処理 : あらゆる種類の処理を示す S 終わり 表示 : ディスプレイ表示を示す このようにフローチャートでは 記号形状自体が処理の意味を示している

More information

解きながら学ぶC++入門編

解きながら学ぶC++入門編 第 1 章 画面 出力 入力 2 問題 1-1 C++ List 1-1p.4 C++ // cout

More information

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU 1. 1.1. 1.2. 1 PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU 2. 2.1. 2 1 2 C a b N: PC BC c 3C ac b 3 4 a F7 b Y c 6 5 a ctrl+f5) 4 2.2. main 2.3. main 2.4. 3 4 5 6 7 printf printf

More information

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

Microsoft PowerPoint - 説明2_演算と型(C_guide2)【2015新教材対応確認済み】.pptx 情報ネットワーク導入ユニット Ⅰ C 言語 演算と型 演算 代入 演算と型 +,-,*,/,% = C 言語では 代入 の意味 vx = a + b; //a+b の結果を vx に代入 型 : int 型 ( 整数 ) double 型 ( 実数 ) 演算での型変換 ( 整数, 実数の混在 ) キャスト演算子 型を一時的に変更 書式指定 :printf("%6d n", a); 加減, 剰余演算

More information

P02.ppt

P02.ppt int If 2 1 ,,, 3 a + b ab a - b ab a * b ab a / b ab a % b ab a + b 4 2 list0201.c /, % /*/ int vx, vy; puts(""); printf("vx"); scanf("%d", &vx); printf("vy"); scanf("%d", &vy); printf("vx + vy = %d\n",

More information

解きながら学ぶC言語

解きながら学ぶC言語 printf 2-5 37 52 537 52 printf("%d\n", 5 + 37); 5370 source program source file.c ex00.c 0 comment %d d 0 decimal -2 -p.6 3-2 5 37 5 37-22 537 537-22 printf("537%d\n", 5-37); function function call ( )argument,

More information

main

main 14 1. 12 5 main 1.23 3 1.230000 3 1.860867 1 2. 1988 1925 1911 1867 void JPcalendar(int x) 1987 1 64 1 1 1 while(1) Ctrl C void JPcalendar(int x){ if (x > 1988) printf(" %d %d \n", x, x-1988); else if(x

More information

新・明解Javaで学ぶアルゴリズムとデータ構造

新・明解Javaで学ぶアルゴリズムとデータ構造 第 3 章 探索 Arrays.binarySearch 743 3-1 探索 探索 searching key 配列 探索 Fig.3-1 b c 75 a 6 4 3 2 1 9 8 2 b 64 23 53 65 75 21 3-1 53 c 5 2 1 4 3 7 4 Fig.3-1 a 763 3-2 線形探索 線形探索 linear search sequential search 2

More information

解きながら学ぶJava入門編

解きながら学ぶJava入門編 44 // class Negative { System.out.print(""); int n = stdin.nextint(); if (n < 0) System.out.println(""); -10 Ÿ 35 Ÿ 0 n if statement if ( ) if i f ( ) if n < 0 < true false true false boolean literalboolean

More information

kiso2-06.key

kiso2-06.key 座席指定があります Linux を起動して下さい 第6回 計算機基礎実習II 計算機基礎実習II 2018 のウェブページか ら 以下の課題に自力で取り組んで下さい 第5回の復習課題(rev05) 第6回の基本課題(base06) 第5回課題の回答例 ex05-2.c 1. キーボードから整数値 a を入力すると a*a*a の値を出力することを繰り返すプログラムを作成しなさい 2. ただし 入力された

More information

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

Microsoft PowerPoint - C言語の復習(配布用).ppt [互換モード] if 文 (a と b の大きい方を表示 ) C 言語 Ⅰ の復習 条件判定 (if, 条件式 ) ループ (for[ 二重まで ], while, do) 配列 ( 次元 次元 ) トレース int a, b; printf( 整数 a: ); scanf( %d, &a); printf( 整数 b: ); scanf( %d, &b); //つのif 文で表現する場合間違えやすい どっちに =

More information

P03.ppt

P03.ppt (2) Switch case 5 1 1 2 1 list0317.c if /*/ intnum; printf(""); scanf("%d", &num); 2 if (num % 3 == 0) puts( 0"); else if (num % 3 == 1) puts(" 1"); else puts( 32"); 3 if list0318.c /*/ intnum; printf("");

More information

P06.ppt

P06.ppt p.130 p.198 p.208 2 1 double weight[num]; double min, max; min = max = weight[0]; for( i= 1; i < NUM; i++ ) if ( weight[i] > max ) max = weight[i]: if ( weight[i] < min ) min = weight[i]: weight 3 maxof(a,

More information

スライド 1

スライド 1 プログラミング 第 3 週 静岡大学工学部機械工学科知能 材料コースロボット 計測情報分野臼杵深光電 精密コース光ナノバイオ分野居波渉 講義の前に 講義資料や演習課題 LiveCampusよりダウンロード可能 成績評価期末試験および課題により行う. 評価の配分は, おおむね試験 90%, 課題 10% である. 再試験期末試験で40 点以上 60 点未満の場合, 再試験となる. 2 月 26 日 (

More information

8 / 0 1 i++ i 1 i-- i C !!! C 2

8 / 0 1 i++ i 1 i-- i C !!! C 2 C 2006 5 2 printf() 1 [1] 5 8 C 5 ( ) 6 (auto) (static) 7 (=) 1 8 / 0 1 i++ i 1 i-- i 1 2 2.1 C 4 5 3 13!!! C 2 2.2 C ( ) 4 1 HTML はじめ mkdir work 作業用ディレクトリーの作成 emacs hoge.c& エディターによりソースプログラム作成 gcc -o fuga

More information

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

‚æ2›ñ C„¾„ê‡Ìš| I 8 10 10 I ( 6 ) 10 10 1 / 23 1 C ( ) getchar(), gets(), scanf() ( ) putchar(), puts(), printf() 1 getchar(), putchar() 1 I ( 6 ) 10 10 2 / 23 1 (getchar 1 1) 1 #include 2 void main(void){ 3 int

More information

kiso2-09.key

kiso2-09.key 座席指定はありません 計算機基礎実習II 2018 のウェブページか 第9回 ら 以下の課題に自力で取り組んで下さい 計算機基礎実習II 第7回の復習課題(rev07) 第9回の基本課題(base09) 第8回試験の結果 中間試験に関するコメント コンパイルできない不完全なプログラムなど プログラミングに慣れていない あるいは複雑な問題は 要件 をバラして段階的にプログラムを作成する exam08-2.c

More information

フローチャートの書き方

フローチャートの書き方 アルゴリズム ( 算法 ) 入門 1 プログラムの作成 機械工学専攻泉聡志 http://masudahp.web.fc2.com/flowchart/index.html 参照 1 何をどのように処理させたいのか どのようなデータを入力し どのような結果を出力させるのか問題を明確にする 2 問題の内容どおりに処理させるための手順を考える ( フローチャートの作成 )~アルゴリズム( 算法 ) の作成

More information

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

[1] #include<stdio.h> main() { printf(hello, world.); return 0; } (G1) int long int float ± ± [1] #include printf("hello, world."); (G1) int -32768 32767 long int -2147483648 2147483647 float ±3.4 10 38 ±3.4 10 38 double ±1.7 10 308 ±1.7 10 308 char [2] #include int a, b, c, d,

More information

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v 1 http://www7.bpe.es.osaka-u.ac.jp/~kota/classes/jse.html kota@fbs.osaka-u.ac.jp /* do-while */ #include #include int main(void) double val1, val2, arith_mean, geo_mean; printf( \n );

More information

untitled

untitled II yacc 005 : 1, 1 1 1 %{ int lineno=0; 3 int wordno=0; 4 int charno=0; 5 6 %} 7 8 %% 9 [ \t]+ { charno+=strlen(yytext); } 10 "\n" { lineno++; charno++; } 11 [^ \t\n]+ { wordno++; charno+=strlen(yytext);}

More information

tuat1.dvi

tuat1.dvi ( 1 ) http://ist.ksc.kwansei.ac.jp/ tutimura/ 2012 6 23 ( 1 ) 1 / 58 C ( 1 ) 2 / 58 2008 9 2002 2005 T E X ptetex3, ptexlive pt E X UTF-8 xdvi-jp 3 ( 1 ) 3 / 58 ( 1 ) 4 / 58 C,... ( 1 ) 5 / 58 6/23( )

More information

18 C ( ) hello world.c 1 #include <stdio.h> 2 3 main() 4 { 5 printf("hello World\n"); 6 } [ ] [ ] #include <stdio.h> % cc hello_world.c %./a.o

18 C ( ) hello world.c 1 #include <stdio.h> 2 3 main() 4 { 5 printf(hello World\n); 6 } [ ] [ ] #include <stdio.h> % cc hello_world.c %./a.o 18 C ( ) 1 1 1.1 hello world.c 5 printf("hello World\n"); 6 } [ ] [ ] #include % cc hello_world.c %./a.out Hello World [a.out ] % cc hello_world.c -o hello_world [ ( ) ] (K&R 4.1.1) #include

More information

gengo1-11

gengo1-11 関数の再帰定義 自然数 n の階乗 n! を計算する関数を定義してみる 引数は整数 返却値も整数 n! = 1*2*3*... * (n 1)*n である ただし 0! = 1 とする int factorial(int n) int i, tmp=1; if( n>0 ) for(i=1; i

More information

コンピュータ工学講義プリント (7 月 17 日 ) 今回の講義では フローチャートについて学ぶ フローチャートとはフローチャートは コンピュータプログラムの処理の流れを視覚的に表し 処理の全体像を把握しやすくするために書く図である 日本語では流れ図という 図 1 は ユーザーに 0 以上の整数 n

コンピュータ工学講義プリント (7 月 17 日 ) 今回の講義では フローチャートについて学ぶ フローチャートとはフローチャートは コンピュータプログラムの処理の流れを視覚的に表し 処理の全体像を把握しやすくするために書く図である 日本語では流れ図という 図 1 は ユーザーに 0 以上の整数 n コンピュータ工学講義プリント (7 月 17 日 ) 今回の講義では フローチャートについて学ぶ フローチャートとはフローチャートは コンピュータプログラムの処理の流れを視覚的に表し 処理の全体像を把握しやすくするために書く図である 日本語では流れ図という 図 1 は ユーザーに 0 以上の整数 n を入力してもらい その後 1 から n までの全ての整数の合計 sum を計算し 最後にその sum

More information

1 4 2 EP) (EP) (EP)

1 4 2 EP) (EP) (EP) 2003 2004 2 27 1 1 4 2 EP) 5 3 6 3.1.............................. 6 3.2.............................. 6 3.3 (EP)............... 7 4 8 4.1 (EP).................... 8 4.1.1.................... 18 5 (EP)

More information

本サンプル問題の著作権は日本商工会議所に帰属します また 本サンプル問題の無断転載 無断営利利用を厳禁します 本サンプル問題の内容や解答等に関するお問 い合わせは 受け付けておりませんので ご了承ください 日商プログラミング検定 STANDARD(C 言語 ) サンプル問題 知識科目 第 1 問 (

本サンプル問題の著作権は日本商工会議所に帰属します また 本サンプル問題の無断転載 無断営利利用を厳禁します 本サンプル問題の内容や解答等に関するお問 い合わせは 受け付けておりませんので ご了承ください 日商プログラミング検定 STANDARD(C 言語 ) サンプル問題 知識科目 第 1 問 ( 本サンプル問題の著作権は日本商工会議所に帰属します また 本サンプル問題の無断転載 無断営利利用を厳禁します 本サンプル問題の内容や解答等に関するお問 い合わせは 受け付けておりませんので ご了承ください 日商プログラミング検定 STANDARD(C 言語 ) サンプル問題 知識科目 第 1 問 ( 知識 4 択 :20 問 ) 1.C 言語ソースプログラムの拡張子は何か 1 c 2 obj 3 exe

More information

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç C (3) if else switch AND && OR (NOT)! 1 BMI BMI BMI = 10 4 [kg]) ( [cm]) 2 bmi1.c Input your height[cm]: 173.2 Enter Input your weight[kg]: 60.3 Enter Your BMI is 20.1. 10 4 = 10000.0 1 BMI BMI BMI = 10

More information

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

C 言語第 3 回 2 a と b? 関係演算子 a と b の関係 関係演算子 等しい a==b 等しくない a!=b より大きい a>b 以上 a>=b より小さい a<b 以下 a<=b 状態 真偽 値 条件が満たされた場合 TRUE( 真 ) 1(0 以外 ) 条件が満たされなかった場合 F C 言語第 3 回 三つの基本構造 ( シラバス 5 6 回目 ) 1 1 順次処理上から順番に実行していく #include int main(void) { long x, y; 最初 長い整数がつかえる 負の数もか だいたい ±21 億まで OK なんだ 掛け算するぞ x = 1000*2000; scanf("%ld", &y); printf("%ld", x*y);

More information

PowerPoint Presentation

PowerPoint Presentation p.130 p.198 p.208 2 double weight[num]; double min, max; min = max = weight[0]; for( i= 1; i i < NUM; i++ ) ) if if ( weight[i] > max ) max = weight[i]: if if ( weight[i] < min ) min = weight[i]: weight

More information

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2  2 B R b I 4 003 4 30 1 ASCII ( ) 0 17 0 NUL 16 DLE SP 0 @ P 3 48 64 80 96 11 p 1 SOH 17 DC1! 1 A Q a 33 49 65 81 97 113 q STX 18 DC " B R b 34 50 66 8 98 114 r 3 ETX 19 DC3 # 3 C S c 35 51 67 83 99 115 s 4 EOT

More information

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * * 2015 2015 07 30 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) +

More information

Microsoft Word - no14.docx

Microsoft Word - no14.docx ex26.c #define MAX 20 int max(int n, int x[]); int num[max]; int i, x; printf(" "); scanf("%d", &x); if(x > MAX) printf("%d %d \n", MAX, MAX); x = MAX; for(i = 0; i < x; i++) printf("%3d : ", i + 1); scanf("%d",

More information

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* ( 2016 2016 07 28 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF : 11011 N N 0 N N 11 1001 N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) 1100100 (2) 1111011 (3) 1110010 (4) 1001011

More information

Taro-プログラミングの基礎Ⅱ(公

Taro-プログラミングの基礎Ⅱ(公 0. 目次 2. プログラムの作成 2. 1 コラッツ問題 自然数 n から出発して n が偶数ならば 2 で割り n が奇数ならば 3 倍して 1 を足す操作を行う この操作を繰り返すと最後に 1 になると予想されている 問題 1 自然数 aの操作回数を求めよ 問題 2 自然数 aから bまでのなかで 最大操作回数となる自然数を求めよ 2. 2 耐久数 正整数の各桁の数字を掛け 得られた結果についても同様の操作を繰り返す

More information

:30 12:00 I. I VI II. III. IV. a d V. VI

:30 12:00 I. I VI II. III. IV. a d V. VI 2018 2018 08 02 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF N N y N x N xy yx : yxxyxy N N x, y N (parse tree) (1) yxyyx (2) xyxyxy (3) yxxyxyy (4) yxxxyxxy N y N x N yx

More information

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

fuga scanf(%lf%*c,&fuga); 改行文字を読み捨てる 10 進数の整数 おまじない取り込んだ値を代入する変数 scanf( %d%*c,&hoge); キーボードから取り込め という命令 1: scanf 1 1: int double scanf %d %lf printf C 2007 5 16 9 1 9 9 if else for 2 hoge scanf("%d%*c",&hoge); ( 1 ) scanf 1 %d 10 2 %*c (p.337) [Enter] &hoge hoge 1 2 10 decimal number d 1 fuga scanf("%lf%*c",&fuga); 改行文字を読み捨てる 10 進数の整数 おまじない取り込んだ値を代入する変数

More information

新版明解C言語 実践編

新版明解C言語 実践編 2 List - "max.h" a, b max List - max "max.h" #define max(a, b) ((a) > (b)? (a) : (b)) max List -2 List -2 max #include "max.h" int x, y; printf("x"); printf("y"); scanf("%d", &x); scanf("%d", &y); printf("max(x,

More information

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

char int float double の変数型はそれぞれ 文字あるいは小さな整数 整数 実数 より精度の高い ( 数値のより大きい より小さい ) 実数 を扱う時に用いる 備考 : 基本型の説明に示した 浮動小数点 とは数値を指数表現で表す方法である 例えば は指数表現で 3 書く 変数 入出力 演算子ここまでに C 言語プログラミングの様子を知ってもらうため printf 文 変数 scanf 文 if 文を使った簡単なプログラムを紹介した 今回は変数の詳細について習い それに併せて使い方が増える入出力処理の方法を習う また 演算子についての復習と供に新しい演算子を紹介する 変数の宣言プログラムでデータを取り扱う場合には対象となるデータを保存する必要がでてくる このデータを保存する場所のことを

More information

プログラミング実習I

プログラミング実習I プログラミング実習 I 03 変数と式 人間システム工学科井村誠孝 m.imura@kwansei.ac.jp 3.1 変数と型 変数とは p.60 C 言語のプログラム中で, 入力あるいは計算された数や文字を保持するには, 変数を使用する. 名前がついていて値を入れられる箱, というイメージ. 変数定義 : 変数は変数定義 ( 宣言 ) してからでないと使うことはできない. 代入 : 変数には値を代入できる.

More information

r07.dvi

r07.dvi 19 7 ( ) 2019.4.20 1 1.1 (data structure ( (dynamic data structure 1 malloc C free C (garbage collection GC C GC(conservative GC 2 1.2 data next p 3 5 7 9 p 3 5 7 9 p 3 5 7 9 1 1: (single linked list 1

More information

情報処理演習 B8クラス

情報処理演習 B8クラス 予定スケジュール ( 全 15 回 ) 1 1. 終了 プログラミング言語の基礎 2. 終了 演算と型 3. 終了 プログラムの流れの分岐 (if 文,switch 文など ) 4. 終了 プログラムの流れの繰返し (do, while, for 文など ) 5. 終了 中間レポート1 6. 終了 配列 7. 終了 関数 8. 終了 文字列 ( 文字列の配列, 文字列の操作 ) 9. 終了 ポインタ

More information

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

Microsoft Word - Cプログラミング演習(11) 第 11 回 (7/2) 4. いくつかのトピック (1) ビットごとの演算子 C 言語には, 次のようなビット単位で演算を行う特別な演算子が用意されている & ビットごとの AND ビットごとの OR ^ ビットごとの XOR( 排他的論理和 ) ~ 1 の補数これらの演算子は文字型と整数型で機能し, 浮動小数点数型では使用できない AND, OR, XOR は, それぞれのオペランドの対応するビットを比較して結果を返す

More information

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

初歩のC言語ターミナル_2014_May.pages C Mac OS X ( Vi Mi) Xcode CD >cd C:\Users\\Desktop gcc first.c C:\Users\\Desktop>gcc -o first first.c gcc first.c C:\Users\\Desktop>first Windows OS VisualStudio VisualStudio VS2012 CD C:\ >cd C:\Users\

More information

ohp07.dvi

ohp07.dvi 19 7 ( ) 2019.4.20 1 (data structure) ( ) (dynamic data structure) 1 malloc C free 1 (static data structure) 2 (2) C (garbage collection GC) C GC(conservative GC) 2 2 conservative GC 3 data next p 3 5

More information

C言語入門

C言語入門 1 C 言語入門 第 4 週 プログラミング言語 Ⅰ( 実習を含む ), 計算機言語 Ⅰ 計算機言語演習 Ⅰ, 情報処理言語 Ⅰ( 実習を含む ) News Visual Studio Code https://code.visualstudio.com/ 2 Microsoft 製プログラミング用テキストエディタ 2015-04-29 にリリースされたばかりのテキストエディタ Windows 以外にも

More information

Microsoft PowerPoint - lec4.ppt

Microsoft PowerPoint - lec4.ppt 本日の内容 繰り返し計算 while 文, for 文 例題 1. 最大公約数の計算例題 2. 自然数の和 while 文例題 3. フィボナッチ数列例題 4. 自然数の和 for 文例題 5. 九九の表繰り返しの入れ子 今日の到達目標 繰り返し (while 文, for 文 ) を使って, 繰り返し計算を行えるようになること ループカウンタとして, 整数の変数を使うこと 今回も, 見やすいプログラムを書くために,

More information

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

Microsoft Word - Cプログラミング演習(8) 第 8 回 (6/11) プログラミングスタイルなど [1] 名前のつけかた グローバル変数にはわかりやすい名前を, ローカル変数には短い名前を 関連性のあるものには関連性のある名前をつけて, 統一しよう 関数には能動的な名前を 名前は的確に 例題 1 次のコードの名前と値の選び方についてコメントせよ? #define TRUE 0? #define FALSE 1?? if ((ch = getchar())

More information

Microsoft Word - no12.doc

Microsoft Word - no12.doc 7.5 ポインタと構造体 構造体もメモリのどこかに値が格納されているのですから 構造体へのポインタ も存在します また ポインタも変数ですから 構造体のメンバに含めることができます まずは 構造体へのポインタをあつかってみます ex53.c /* 成績表 */ #define IDLENGTH 7 /* 学籍番号の長さ */ #define MAX 100 /* 最大人数 */ /* 成績管理用の構造体の定義

More information

Taro-リストⅠ(公開版).jtd

Taro-リストⅠ(公開版).jtd 0. 目次 1. 再帰的なデータ構造によるリストの表現 1. 1 リストの作成と表示 1. 1. 1 リストの先頭に追加する方法 1. 1. 2 リストの末尾に追加する方法 1. 1. 3 昇順を保存してリストに追加する方法 1. 2 問題 問題 1 問題 2-1 - 1. 再帰的なデータ構造によるリストの表現 リストは データの一部に次のデータの記憶場所を示す情報 ( ポインタという ) を持つ構造をいう

More information

明解Javaによるアルゴリズムとデータ構造

明解Javaによるアルゴリズムとデータ構造 74 searching 3 key Fig.3-1 75 2を探索 53を探索 3-1 5 2 1 4 3 7 4 を探索 Fig.3-1 76 3 linear searchsequential search 2 Fig.3-2 0 ❶ ❷ ❸ 配列の要素を先頭から順に走査していく 探索すべき値と等しい要素を発見 Fig.3-2 6 4 3 2 3-2Fig.3-3 77 5 Fig.3-3 0

More information

Microsoft PowerPoint - 14Chap17.ppt

Microsoft PowerPoint - 14Chap17.ppt 17.1 do-while 文 p.161 例 17.1.1 p.22 例 5.1.1 第 17 章その他の制御文 17.1 do-while 文 17.2 goto 文とラベル 17.3 break 文による繰返し制御 17.4 continue 文による繰返し制御 /* ex17_1_1.c */ do while (i < 10); 条件を満たさなくても 1 回は実行 i = 10; とすると違いがわかる

More information

数値計算

数値計算 数値計算 垣谷公徳 17 号館 3 階電子メール : kimi@ee.ous.ac.jp プログラミング言語の一般論 データ型 ( 定数と変数 配列 ) 代入 基本演算 ( 四則演算 ) 入出力 分岐 繰返処理 関数 外部手続き 1 2 入力関数 入出力 getchar, getc, fgetc ; 一文字入力 gets, fgets, fread ; 文字列 ( データ列 ) 入力 scanf,

More information

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

Microsoft Word - Cプログラミング演習(3) 第 3 回 (5/7) 5. ループ ( 繰り返し ) 1 for 文 例題 1-15 正の数 n をキーボードから入力すると,1 から n までの整数の和を出力するプログラムをつくりなさい 出力結果 1-15 2 以上の整数を入力してください! 357 1 + + 357 = 63903 考え方合計を保持する変数を long 型で宣言し, 入力した数値 n までループ処理で累積する 正しい数値が入力されたとき

More information

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B A/B (2018/10/19) Ver. 1.0 kurino@math.cst.nihon-u.ac.jp http://edu-gw2.math.cst.nihon-u.ac.jp/ kurino/2018/soft/soft.html 2018 10 19 A/B 1 2018 10 19 2 1 1 1.1 OHP.................................... 1

More information

橡Pro PDF

橡Pro PDF 1 void main( ) char c; /* int c; */ int sum=0; while ((c = getchar())!= EOF) if(isdigit(c) ) sum += (c-'0'); printf("%d\n", sum); main()int i,sum=0; for(i=0;i

More information

C 言語固有の命令で全部で32 個 の関数C 言語第 1 回 C 言語って?( シラバス 1 2 回目 ) 関数型言語 コンピュータに実行してもらう命令はすべて関数の中に記述されている 関数がプロ グラム

C 言語固有の命令で全部で32 個 の関数C 言語第 1 回 C 言語って?( シラバス 1 2 回目 ) 関数型言語 コンピュータに実行してもらう命令はすべて関数の中に記述されている 関数がプロ グラム 1 Visual Studio 2010 Express の使用法 (PDF ファイルでの配布 :VS2010.pdf) http://www.sp.u-tokai.ac.jp/~yasue/ffn/vs2010.pdf 物理学科のホームページ (http://www.sp.u-tokai.ac.jp/) 右下の 研究室サイト の 素粒子理論. 安江研 から移動 左側のメニュー C 言語 から移動

More information

C言語7

C言語7 C 言語 7 ポインタ アドレスを出力 int a; a=5; printf(" 変数 aの値は %dです n", a); printf(" 変数 aのアドレスは %pです n", &a); 実行結果 変数 a の値は 5 です 変数 a のアドレスは 0038FAC4 です 変数 a の値は 15 です 変数 a のアドレスは 0038FAC4 です 注 アドレスの値は実行環境やプログラムの実行状況により異なります

More information

1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main

1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf(hello World!!\n); return 0; 戻り値 1: main() 2.2 C main C 2007 5 29 C 1 11 2 2.1 main() 1 FORTRAN C main() main main() main() 1 return 1 1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return

More information

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

printf(5つの整数を入力して下さい \n); /* データ入力 */ for( /*** 02 ***/ ){ printf(%dつ目の入力 :,i+1); scanf(%d, /*** 03 ***/ ); sum=dat[0]; /* 合計値の初期設定 */ n_max= 0 電子情報競技会ソフトウェア課題 1 Question_1 プロジェクト内のソースプログラムの /*** XX ***/ に適当な語句 式等を入れ プログラムを完成させなさい ここで 同じ番号の /*** XX ***/ には同じ語句 式等が入る /*** XX ***/ の部分以外は書き換えてはならないが 別のソースファイルにてテストしてもかまわない [ プログラムの説明 ] 1. 処理内容 2 桁の整数データ

More information

untitled

untitled II 4 Yacc Lex 2005 : 0 1 Yacc 20 Lex 1 20 traverse 1 %% 2 [0-9]+ { yylval.val = atoi((char*)yytext); return NUM; 3 "+" { return + ; 4 "*" { return * ; 5 "-" { return - ; 6 "/" { return / ; 7 [ \t] { /*

More information

Taro-再帰関数Ⅱ(公開版).jtd

Taro-再帰関数Ⅱ(公開版).jtd 0. 目次 6. 2 項係数 7. 二分探索 8. 最大値探索 9. 集合 {1,2,,n} 上の部分集合生成 - 1 - 6. 2 項係数 再帰的定義 2 項係数 c(n,r) は つぎのように 定義される c(n,r) = c(n-1,r) + c(n-1,r-1) (n 2,1 r n-1) = 1 (n 0, r=0 ) = 1 (n 1, r=n ) c(n,r) 0 1 2 3 4 5

More information

明解Java入門編

明解Java入門編 1 Fig.1-1 4 Fig.1-1 1-1 1 Table 1-1 Ease of Development 1-1 Table 1-1 Java Development Kit 1 Java List 1-1 List 1-1 Chap01/Hello.java // class Hello { Java System.out.println("Java"); System.out.println("");

More information

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

Microsoft Word - Cプログラミング演習(12) 第 12 回 (7/9) 4. いくつかのトピック (5)main 関数の引数を利用したファイル処理 main 関数は, 起動する環境から引数を受け取ることができる 例えば 次に示すように,main 関数に引数を用いたプログラムを作成する 01 /* sample */ 02 /* main 関数の引数 */ 03 #include 04 05 main(int argc, char

More information

Microsoft PowerPoint - 計算機言語 第7回.ppt

Microsoft PowerPoint - 計算機言語 第7回.ppt 計算機言語第 7 回 長宗高樹 目的 関数について理解する. 入力 X 関数 f 出力 Y Y=f(X) 関数の例 関数の型 #include int tasu(int a, int b); main(void) int x1, x2, y; x1 = 2; x2 = 3; y = tasu(x1,x2); 実引数 printf( %d + %d = %d, x1, x2, y);

More information

kiso2-03.key

kiso2-03.key 座席指定はありません Linux を起動して下さい 第3回 計算機基礎実習II 2018 のウェブページか ら 以下の課題に自力で取り組んで下さい 計算機基礎実習II 第2回の復習課題(rev02) 第3回の基本課題(base03) 第2回課題の回答例 ex02-2.c include int main { int l int v, s; /* 一辺の長さ */ /* 体積 v

More information

計算機プログラミング

計算機プログラミング プログラミング言語 C 第 6 講 制御 ( 選択 ) フローチャートと C 言語 図形と命令の対応表 図形 C 言語 図形 C 言語 START main()? if END? else 整数型変数 int? switch printf case scanf break 選択 (1) if else 文 条件 処理 A 処理 B 構文 if ( 条件 ) IF THEN ELSE 型 処理 A;

More information

DVIOUT

DVIOUT 5.2. 流れ図 105 5.2 流れ図 流れ図 (flow chart) はアルゴリズムを図式化したもので コンピュータの手順となるデータの流れ 判定 実行の推移などを流れ図記号 4 を用いて描きます 流れ図のようにアルゴリズムを図式化することで 問題の定義や分析または解法がより明確となり プログラムの設計や作成に非常に役立ちます また 第三者にも的確にアルゴリズムを伝えることができます それでは

More information

Microsoft PowerPoint - 3.pptx

Microsoft PowerPoint - 3.pptx 条件分岐 ( if 文 ) 第 2 回の講義資料で出題した練習問題や演習問題の計算は, 勿論電卓でもでき, わざわざプログラムを作ってまでするほどの計算ではありませんでした. プログラムによる計算と電卓の計算の きな違いの つが, プログラムには, 条件による処理の分岐, 繰り返しがあることです. まず今回は, 条件による処理の分岐 ( 処理の切り替え と う が適切かもしれません ) の書き について学んでいきます.

More information

Taro-ファイル処理(公開版).jtd

Taro-ファイル処理(公開版).jtd ファイル処理 0. 目次 1. はじめに 2. ファイル内容の表示 3. ファイル内容の複写 3. 1 文字単位 3. 2 行単位 4. 書式付き入出力 5. 文字配列への入出力 6. 課題 6. 1 課題 1 ( ファイル圧縮 復元 ) - 1 - 1. はじめに ファイル処理プログラムの形は次のようになる #include main() { FILE *fp1,*fp2; ファイルポインタの宣言

More information

:30 12:00 I. I VI II. III. IV. a d V. VI

:30 12:00 I. I VI II. III. IV. a d V. VI 2017 2017 08 03 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF X [ S ] a S S ; X X X, S [, a, ], ; BNF X (parse tree) (1) [a;a] (2) [[a]] (3) [a;[a]] (4) [[a];a] : [a] X 2 222222

More information

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I  Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~alse I Exercise on Programming I http://bit.ly/oitprog1 1, 2 of 14 ( RD S ) I 1, 2 of 14 1 / 44 Ruby Ruby ( RD S ) I 1, 2 of 14 2 / 44 7 5 9 2 9 3 3 2 6 5 1 3 2 5 6 4 7 8 4 5 2 7 9 6 4 7 1 3 ( RD S ) I 1, 2

More information

関数 C 言語は関数の言語 関数とは 関数の定義 : f(x) = x * x ; 使うときは : y = f(x) 戻り値 引数

関数 C 言語は関数の言語 関数とは 関数の定義 : f(x) = x * x ; 使うときは : y = f(x) 戻り値 引数 関数 C 言語は関数の言語 関数とは 関数の定義 : f(x) = x * x ; 使うときは : y = f(x) 戻り値 引数 関数の定義 戻り値の型 関数名 引数の型 引数の名前 int funcname ( int a, char b) { int c ; c = a * b ; return c ; 引数の型 引数の名前 戻り値 戻り値の型は int 変数 c の型も int return

More information

Microsoft Word - no206.docx

Microsoft Word - no206.docx 3.2 双方向リスト 今までのリストは 前から順にたどることしかできませんでした 今度は逆にもたどることができる 双方向リストを扱います この場合は 構造体には次を表すポインタの他に前を表すポインタを持つ ことになります 今回は最初と最後をポインタを使うと取り扱いが面倒になるので 最初 (start) と最後 (end) を どちらとも構造体 ( 値は意味を持たない ) を使うことにします こうすることによって

More information

ポインタ変数

ポインタ変数 プログラミング及び実習 5 馬青 1 文字処理 数値処理 : 整数 浮動小数点数 単一の文字は と ( シングルクォーテーション ) で囲んで表現される 文字のデータ型は char または int である int を用いたほうが ライブラリの関数の引数の型と一致する 以下は全部 int の使用に統一する 従って int ch; で文字変数を宣言しておくと ch= A ; のように ch に文字 A

More information

( ) ( ) 30 ( ) 27 [1] p LIFO(last in first out, ) (push) (pup) 1

( ) ( ) 30 ( ) 27 [1] p LIFO(last in first out, ) (push) (pup) 1 () 2006 2 27 1 10 23 () 30 () 27 [1] p.97252 7 2 2.1 2.1.1 1 LIFO(last in first out, ) (push) (pup) 1 1: 2.1.2 1 List 4-1(p.100) stack[] stack top 1 2 (push) (pop) 1 2 void stack push(double val) val stack

More information

Microsoft Word - no15.docx

Microsoft Word - no15.docx 7. ファイルいままでは プログラムを実行したとき その結果を画面で確認していました 簡単なものならそれでもいいのですか 複雑な結果は画面で見るだけでなく ファイルに保存できればよいでしょう ここでは このファイルについて説明します 使う関数のプロトタイプは次のとおりです FILE *fopen(const char *filename, const char *mode); ファイルを読み書きできるようにする

More information

C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 新装版 1 刷発行時のものです.

C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます.  このサンプルページの内容は, 新装版 1 刷発行時のものです. C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. http://www.morikita.co.jp/books/mid/009383 このサンプルページの内容は, 新装版 1 刷発行時のものです. i 2 22 2 13 ( ) 2 (1) ANSI (2) 2 (3) Web http://www.morikita.co.jp/books/mid/009383

More information

3. 標準入出力

3. 標準入出力 Linux にログインして待っていること以下のサイトを開いておくこと http://www-it.sci.waseda.ac.jp/teachers/w483692/cpr1/ 4. 条件分岐 制御構文 (1) C プログラミング入門基幹 2 ( 月 4) 制御構造 control flow 逐次実行 o 関数は ブロック内の文を書かれた順に実行する 条件分岐 o 変数などがある条件を満たす場合だけ実行する

More information

gengo1-6

gengo1-6 繰り返し処理 while 文 do 文 所定回反復 ( 特定回数の繰り返し ) には for 文を用いた ある手順を 例えば 10 回 繰り返す といった繰り返し処理 問題を 10 題解け といった繰り返し 繰り返し回数が明示的に決まらない場合には while 文 do 文を用いる ある条件が満たされている限り繰り返す といった繰り返し処理では繰り返し回数は決まらない 不定回反復 例えば 理解できるまで問題を繰り返し解け

More information

program7app.ppt

program7app.ppt プログラム理論と言語第 7 回 ポインタと配列, 高階関数, まとめ 有村博紀 吉岡真治 公開スライド PDF( 情報知識ネットワーク研 HP/ 授業 ) http://www-ikn.ist.hokudai.ac.jp/~arim/pub/proriron/ 本スライドは,2015 北海道大学吉岡真治 プログラム理論と言語, に基づいて, 現著者の承諾のもとに, 改訂者 ( 有村 ) が加筆修正しています.

More information

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

Microsoft PowerPoint - CproNt02.ppt [互換モード] 第 2 章 C プログラムの書き方 CPro:02-01 概要 C プログラムの構成要素は関数 ( プログラム = 関数の集まり ) 関数は, ヘッダと本体からなる 使用する関数は, プログラムの先頭 ( 厳密には, 使用場所より前 ) で型宣言 ( プロトタイプ宣言 ) する 関数は仮引数を用いることができる ( なくてもよい ) 関数には戻り値がある ( なくてもよい void 型 ) コメント

More information

C C UNIX C ( ) 4 1 HTML 1

C C UNIX C ( ) 4 1 HTML 1 C 2007 4 18 C UNIX 1 2 1 1.1 C ( ) 4 1 HTML 1 はじめ mkdir work 作業用ディレクトリーの作成 emacs hoge.c& エディターによりソースプログラム作成 gcc -o fuga hoge.c コンパイルにより機械語に変換 コンパイルエラー./fuga 実行 実行時エラー 完成 1: work hooge.c fuga 1 4 4 1 1.

More information

A/B (2018/06/08) Ver kurino/2018/soft/soft.html A/B

A/B (2018/06/08) Ver kurino/2018/soft/soft.html A/B A/B (2018/06/08) Ver. 1.0 kurino@math.cst.nihon-u.ac.jp http://edu-gw2.math.cst.nihon-u.ac.jp/ kurino/2018/soft/soft.html 2018 6 8 A/B 1 2018 6 8 2 1 1 1.1 OHP.................................... 1 1.2

More information

2) TA Hercules CAA 5 [6], [7] CAA BOSS [8] 2. C II C. ( 1 ) C. ( 2 ). ( 3 ) 100. ( 4 ) () HTML NFS Hercules ( )

2) TA Hercules CAA 5 [6], [7] CAA BOSS [8] 2. C II C. ( 1 ) C. ( 2 ). ( 3 ) 100. ( 4 ) () HTML NFS Hercules ( ) 1,a) 2 4 WC C WC C Grading Student programs for visualizing progress in classroom Naito Hiroshi 1,a) Saito Takashi 2 Abstract: To grade student programs in Computer-Aided Assessment system, we propose

More information

ポインタ変数

ポインタ変数 プログラミング及び実習 5 馬青 1 文字処理 数値処理 : 整数 浮動小数点数 単一の文字は と ( シングルクォーテーション ) で囲んで表現される 文字のデータ型は char または int である int を用いたほうが ライブラリの関数の引数の型と一致する 以下は全部 int の使用に統一する 従って int ch; で文字変数を宣言しておくと ch= A ; のように ch に文字 A

More information