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

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

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

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

P03.ppt

P05.ppt

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

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

/* 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

新・明解C言語 実践編

新版明解C言語入門編

PowerPoint Presentation

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

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

新版明解C言語 実践編

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 ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

main

解きながら学ぶC言語

‚æ4›ñ

P06.ppt

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) * *

P02.ppt

明解Java入門編

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

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

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡

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

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

r07.dvi

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

ohp07.dvi

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

C C UNIX C ( ) 4 1 HTML 1

untitled

プログラミング基礎

新・明解C言語 ポインタ完全攻略

新・明解Java入門

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

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

次に示す数値の並びを昇順にソートするものとする このソートでは配列の末尾側から操作を行っていく まず 末尾の数値 9 と 8 に着目する 昇順にソートするので この値を交換すると以下の数値の並びになる 次に末尾側から 2 番目と 3 番目の 1

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

16soukatsu_p1_40.ai

ex14.dvi

O(N) ( ) log 2 N

Taro-最大値探索法の開発(公開版

yacc.dvi

Microsoft Word - no15.docx

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

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

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

Microsoft PowerPoint - lec4.ppt

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

2004

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >=

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

C B

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

kiso2-09.key

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1:

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

演習課題No12

プログラミング基礎

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

1 4 2 EP) (EP) (EP)

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

1. 52

扉 序文 目次DVD用 .indd

すぐできる冬の省エネ・節電ガイド

”Žfi¶‰s‚ÒŒh”~”ŒŠá‘WŁ\”ƒ



untitled

Microsoft Word - no14.docx

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

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

DVIOUT

tuat1.dvi

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

BW BW

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

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

Microsoft Word - no206.docx

debug ( ) 1) ( ) 2) ( ) assert, printf ( ) Japan Advanced Institute of Science and Technology

ex01.dvi

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

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

/

17 1. strucr Potter ( ) Harry Potter and the Philosopher s Stone 1997 English Title : Harry Potter and the Philosopher s Stone : : 1997 #include<stdio

untitled

Taro-2分探索木Ⅱ(公開版).jtd

kiso2-03.key


untitled

橡07第1章1_H160203_.PDF

橡Pro PDF

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

ohp03.dvi


情報処理演習 B8クラス

XMPによる並列化実装2

Transcription:

Algorithms and Data Structures in C

4 algorithm List - /* */ #include <stdio.h> List - int main(void) { int a, b, c; int max; /* */ Ÿ 3Ÿ 2Ÿ 3 printf(""); printf(""); printf(""); scanf("%d", &a); scanf("%d", &b); 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 () max a (2) b max b (3) c max c flowchart Fig.- Yes No if

5 a max b max No Yes b max b c a c max Yes No c max Fig.- b > max c > max Yes p.22 a max a max a, b, c, 3, 2 a, b, c, 2, 3 3, 2, 5, 5, 5 5, 3, 5 a, b, c, 3, 2 6, 0, 7-0, 00, 0 b c a 4 4 4 4 4 4 4 4 4

6 Fig.-2 a b a b b c a c b c a c a c c a b a b c a b c a c c a b a b c a b c a c b a c b a c a c b c b a c b a c b c c b a b c a b c a Fig.-2 3 List -2 3 3 function max3 int a, b, c int main max3 3

7 /* */ #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); List -2 max3(3,2,) = 3 max3(3,2,2) = 3 max3(3,,2) = 3 max3(3,2,3) = 3 max3(2,,3) = 3 max3(3,3,2) = 3 max3(3,3,3) = 3 max3(2,2,3) = 3 max3(2,3,) = 3 max3(2,3,2) = 3 max3(,3,2) = 3 max3(2,3,3) = 3 max3(,2,3) = 3 int main(void) { printf("max3(%d,%d,%d) = %d\n", 3, 2,, max3(3, 2, )); /* a b c */ printf("max3(%d,%d,%d) = %d\n", 3, 2, 2, max3(3, 2, 2)); /* a b c */ printf("max3(%d,%d,%d) = %d\n", 3,, 2, max3(3,, 2)); /* a c b */ printf("max3(%d,%d,%d) = %d\n", 3, 2, 3, max3(3, 2, 3)); /* a c b */ printf("max3(%d,%d,%d) = %d\n", 2,, 3, max3(2,, 3)); /* c a b */ printf("max3(%d,%d,%d) = %d\n", 3, 3, 2, max3(3, 3, 2)); /* a b c */ printf("max3(%d,%d,%d) = %d\n", 3, 3, 3, max3(3, 3, 3)); /* a b c */ printf("max3(%d,%d,%d) = %d\n", 2, 2, 3, max3(2, 2, 3)); /* c a b */ printf("max3(%d,%d,%d) = %d\n", 2, 3,, max3(2, 3, )); /* b a c */ printf("max3(%d,%d,%d) = %d\n", 2, 3, 2, max3(2, 3, 2)); /* b a c */ printf("max3(%d,%d,%d) = %d\n",, 3, 2, max3(, 3, 2)); /* b c a */ printf("max3(%d,%d,%d) = %d\n", 2, 3, 3, max3(2, 3, 3)); /* b c a */ printf("max3(%d,%d,%d) = %d\n",, 2, 3, max3(, 2, 3)); /* c b a */ return (0); JIS X000 int min3(int a, int b, int c); int med3(int a, int b, int c);

8 n n 2 + 2 n 3 + 2 + 3 + 2 + + n sum Fig.-3 0 sum i i n No Yes sum + i sum i + i Fig.-3 List -3 while while ( ) 0 0 do p.24

/* */, 2,, n while #include <stdio.h> int main(void) { int i, n; int sum; /* */ puts(" n "); printf("n"); scanf("%d", &n); sum = 0; i = ; List -3 n n0ÿ 0 55 9 while (i <= n) { /* i n */ sum += i; /* sum i */ i++; /* i */ printf(" %d %d\n", n, sum); return (0); i n n i sum Fig.-4 i n sum += ++ i n while i n n + sum i 0 2 3 3 6 4 0 5 5 6 Fig.-4

20 while for List -4 /* */, 2,, n for #include <stdio.h> int main(void) { int i, n; int sum; /* */ puts(" n "); printf("n"); scanf("%d", &n); List -4 n n0ÿ 0 55 sum = 0; for (i = ; i <= n; i++) { /* i =, 2,, n */ sum += i; /* sum i */ printf(" %d %d\n", n, sum); return (0); Fig.-5 loop limit i :,, n i n Column - while for while for for ( ; 2 ; 3 ) ; while ( 2 ) { 3 ; for 2 3 2

2 0 sum i,, n sum + i sum Fig.-5 i n i n for n + Fig.-6 i, 2,, n sum + i sum Fig.-6 List -4 n 7 7 28 + 2 + 3 + 4 + 5 + 6 + 7 = 28 a, b int sumof(int a, int b); a b a 3 b 5 2 a 6 b 4 5

22 Column -2 flowchart JIS X02 program flowchart data process predefined process decision

23 switch loop limit line terminator

24 n -5-5 0 n List -5 /* */, 2,, n n #include <stdio.h> int main(void) { int i, n; int sum; /* */ List -5 n n-5ÿ n8ÿ 8 36 puts(" n "); do { printf("n"); scanf("%d", &n); while (n <= 0); sum = 0; for (i = ; i <= n; i++) { sum += i; /* sum i */ printf(" %d %d\n", n, sum); return (0); n 0 n do Fig.-7 n 0 do n (a) (b) (b) (a)

25 (a) n Yes n 0 No (b) n n 0 Fig.-7 35 3 34 4 a, b b - a b a a5ÿ b4ÿ a b7ÿ b - a 2 Column -3 List -2 max3 argument parameter

26 4 * List -6 /* */ #include <stdio.h> int main(void) { int i, j, n; printf(" "); scanf("%d", &n); List -6 5Ÿ * ** *** **** ***** for (i = ; i <= n; i++) { for (j = ; j <= i; j++) putchar('*'); putchar('\n'); return (0); Fig.-8 n 5 for i n for j i i j * i 2 j 2 ** i 3 j 3 *** i 4 j 4 **** i 5 j 5 ***** n n n *

27 i,, n j,, i * Fig.-8 void trilb(int n); void trilu(int n); void triru(int n); void trirb(int n); n void spira(int n); n (n - ) * 2 + * * *** ***** ******* n void npira(int n); n n % 0 222 33333 4444444