2.1 programming09 programming /******************************** 2 3 ********************************/ 4 5 #include <stdio.h> 6 7 int sum(int x

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

P05.ppt

超初心者用

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

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

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

kiso2-09.key

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

P03.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 <<

PowerPoint Presentation

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

P06.ppt

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

tuat1.dvi

main

‚æ4›ñ

joho07-1.ppt

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

新版明解C言語入門編

C C UNIX C ( ) 4 1 HTML 1

P02.ppt

C 2 / 21 1 y = x 1.1 lagrange.c 1 / Laglange / 2 #include <stdio.h> 3 #include <math.h> 4 int main() 5 { 6 float x[10], y[10]; 7 float xx, pn, p; 8 in

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

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

2 P.S.P.T. P.S.P.T. wiki 26

解きながら学ぶC言語

ex14.dvi

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

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

double float

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

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

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

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

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

PowerPoint Presentation

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

A/B (2010/10/08) Ver kurino/2010/soft/soft.html A/B

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

配列, 関数, 構造体

untitled

untitled


PowerPoint プレゼンテーション - 物理学情報処理演習

: CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and Technology

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

XMPによる並列化実装2

-2-

memo

ohp03.dvi

Microsoft Word - 03

[ 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:

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

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 >=

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

Microsoft Word - no206.docx

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

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

x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x i ) A(x i ) = h 2 {f(x i) + f(x i+1 ) = h {f(a + i h) + f(a + (i + 1) h), (2) 2 a b n A(x i )

C言語講座 後半

Microsoft Word - no15.docx

/* sansu1.c */ #include <stdio.h> main() { int a, b, c; /* a, b, c */ a = 200; b = 1300; /* a 200 */ /* b 200 */ c = a + b; /* a b c */ }

kiso2-03.key

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

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

Informatics 2010.key

Microsoft Word - 3new.doc

Microsoft Word - C.....u.K...doc

cp-7. 配列

Informatics 2015

1.1 1 C IIA $ cd comp3a %endminipage ~/comp3a mkdir $ mkdir comp3a $ cd comp3a C.c Emacs Cntrol x Control s 2 Emacs Control-x Control-f Control-


memo

Informatics 2014

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

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

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

プログラミング及び演習 第1回 講義概容・実行制御

講習No.12

/*Source.cpp*/ #include<stdio.h> //printf はここでインクルードして初めて使えるようになる // ここで関数 average を定義 3 つの整数の平均値を返す double 型の関数です double average(int a,int b,int c){

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

Microsoft PowerPoint - lec4.ppt

Prog1_6th

<4D F736F F D20438CBE8CEA8D758DC03389F0939A82C282AB2E646F63>

Microsoft Word - no14.docx

joho09.ppt

第7章 有限要素法のプログラミング

講習No.10

r03.dvi

untitled

プログラミング及び演習 第1回 講義概容・実行制御

1 4 2 EP) (EP) (EP)

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

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() 2 double *a[ ]; double 1 malloc() dou

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

Microsoft PowerPoint - 11.pptx

バイオプログラミング第 1 榊原康文 佐藤健吾 慶應義塾大学理工学部生命情報学科

プログラミング実習I

Transcription:

1 C [1] 2 (,,...) : int f(float a, double b); 1 1 ( int ) 2.2 7 ( ) 24 30 x,y 29 return ( ); 18 x,y sum return z ( ) 1 24 1

2.1 programming09 programming09 2.2 1 /******************************** 2 3 ********************************/ 4 5 #include <stdio.h> 6 7 int sum(int x, int y); 8 9 int main(){ 10 int x,y,z; 11 12 printf(" :"); 13 scanf("%d", &x); 14 15 printf(" :"); 16 scanf("%d", &y); 17 18 z=sum(x,y); 19 20 printf(" %d \n",z); 21 return 0; 22 } 23 24 int sum(int x, int y){ 25 /* */ 26 int a; 27 28 a=x+y; 29 return a; 30 } 2.3 func-example.c exfunc > gcc -o exfunc func-example.c 2

2.4 2.5 2.6 2.6.1 2.2 ( ) ( ) ( ) 0 3 - - ( )#include ( 1) 2.2 my-calc #include 2.2 ( 2 ) #include<stdio.h> < > ( ) 1: include :my-cal :my-calc ( ).h.c(c ) include 2.2 ( 3 ) 3

2: include 3: include ( ) ( ) (.o) printf scanf ( ) ( ) ( ) ( )= ( )+ ( 4) 3 ( ) #include my-calc.c > gcc -o func-example func-example.c my-calc.c my-calc.c > gcc -c my-calc.c my-calc.o > gcc -o func-example func-example.c my-calc.o ( my-calc.c ( ) ) 4

4: ( ) 3.1 2.2 func-example.c my-calc.h my-calc.c 3.2 > gcc -c my-calc.c func-example > gcc -o func-example func-example.c my-calc.o func-example > gcc -o func-example func-example.c my-calc.c 3.3 4-3 - [2] 3 (3 ) ( ) 4.2 9 35 28 5

4.1 bandit.h bandit00.o 4.2 [1] 1 /******************************************************* 2 (3 ) 3 *******************************************************/ 4 5 #include <stdio.h> /* */ 6 #include <stdlib.h> /* */ 7 #include "bandit.h" /* */ 8 9 double armselect3(int first, int second, int third); 10 11 int main(){ 12 int num_arm, loop, arm_select, selection[3]; 13 double total_reward; 14 15 init_bandit(); /* */ 16 17 num_arm = get_arm_num();/* */ 18 printf(" %d \n",num_arm); 19 20 /* (3 ) */ 21 for(loop=0 ; loop<3 ; loop++){ 22 printf(" [1-%d]:",num_arm); 23 scanf("%d", &arm_select); 24 selection[loop] = arm_select; 25 } 26 27 /* armselect3 */ 28 total_reward = armselect3(selection[0], selection[1], selection[2]); 29 30 printf(" :%lf\n",total_reward); 31 32 return 0; 33 } 6

34 35 double armselect3(int first, int second, int third){ 36 int loop; 37 double total; 38 39 /* 3 */ 40 total = bandit(first); 41 total = total + bandit(second); 42 total = total + bandit(third); 43 44 return total; 45 } 4.3 gameplay-armselect3.c gameplay-armselect3 > gcc -o gameplay-armselect3 gameplay-armselect3.c bandit00.o 4.4 3 4.5 4.5.1 armselect3 armselect3.h armselect3.c 4.5.2 4.2 3 5 10 armselect5, armselect10 5 4.2 3 7

5.1 10 42 [3] 12 40 10 12 32 ( ) (double array[10] 10 ) 10 (12 ) num try 5.1 [1] 1 /******************************************************* 2 ( ) 3 *******************************************************/ 4 5 #include <stdio.h> /* */ 6 #include <stdlib.h> /* */ 7 #include "bandit.h" /* */ 8 9 /* num_try (selection[i] i+1 */ 10 double armselect(int selection[], int num_try); 11 /* 12 double armselect(int* selection, int num_try); 13 */ 14 15 int main(){ 16 int num_arm, loop, arm_select, selection[3]; 17 double total_reward; 18 19 init_bandit(); /* */ 20 21 num_arm = get_arm_num();/* */ 22 printf(" %d \n",num_arm); 23 24 /* (3 ) */ 25 for(loop=0 ; loop<3 ; loop++){ 26 printf(" [1-%d]:",num_arm); 27 scanf("%d", &arm_select); 28 selection[loop] = arm_select; 29 } 8

30 31 /* armselect (3 ) */ 32 total_reward = armselect(selection, 3); 33 34 printf(" :%lf\n",total_reward); 35 36 return 0; 37 } 38 39 /* 40 double armselect(int* selection, int num_try){ 41 */ 42 double armselect(int selection[], int num_try){ 43 int loop; 44 double total; 45 46 /* num_try */ 47 total=0.0; 48 for(loop=0 ; loop<num_try ; loop++){ 49 total = total + bandit(selection[loop]); 50 } 51 52 return total; 53 } 5.2 gameplay-arrayselect3.c gameplay-arrayselect3 > gcc -o gameplay-arrayselect3 gameplay-arrayselect3.c bandit00.o 5.3 3 5.4 5.4.1 armselect arrayselect.h arrayselect.c 9

5.4.2 5.1 3 5 10 5.4.3 5.1 6 (,,...) : int f(float a, double b); 1 1 3 armselect3 armselect 3 3 3 6.1 26 35 42 52 25 27 ( ) pointer pointerarray int* p ( ) 6.1 1 /******************************** 2 3 ********************************/ 4 5 #include <stdio.h> 6 #include <stdlib.h> 10

7 8 int normal(int input); 9 int pointer(int* p); 10 int pointerarray(int* p); 11 12 int main(){ 13 /* */ 14 int input; 15 /* */ 16 int *pointer1, *pointer2; 17 /* ( ) */ 18 int *parray; 19 /* */ 20 int array[10]; 21 22 23 /* */ 24 input = -1; 25 printf("input = %d\n",input); 26 normal(input); 27 printf("input = %d\n",input); 28 29 /* */ 30 31 /* pointer1 input */ 32 pointer1 = &input; 33 *pointer1=-2; 34 printf("*pointer1 = %d\n",*pointer1); 35 pointer(pointer1); 36 printf("*pointer1 = %d\n",*pointer1); 37 38 /* pointer2 */ 39 pointer2 = malloc(sizeof(int)); 40 *pointer2=-3; 41 printf("*pointer2 = %d\n",*pointer2); 42 pointer(pointer2); 43 printf("*pointer2 = %d\n",*pointer2); 44 45 /* ( ) */ 46 parray = malloc(sizeof(int)*10); /* 10 */ 47 /* parray[2] parray[3] */ 48 *(parray+2)=-4; /* parray[2] */ 49 parray[3]=-5; /* *(parray+3) */ 11

50 51 printf("parray[2]:parray[3]=%d:%d\n",parray[2],parray[3]); 52 pointerarray(parray); 53 printf("parray[2]:parray[3]=%d:%d\n",parray[2],parray[3]); 54 55 /* */ 56 /* array[2] array[3] */ 57 array[2]=-6; 58 array[3]=-7; 59 60 printf("array[2]:array[3]=%d:%d\n",array[2],array[3]); 61 pointerarray(array); /* */ 62 printf("array[2]:array[3]=%d:%d\n",array[2],array[3]); 63 64 free(pointer2); 65 free(parray); 66 return; 67 } 68 69 int normal(int input){ 70 input = 100; 71 72 return 0; 73 } 74 75 int pointer(int* p){ 76 *p = 200; 77 78 return 0; 79 } 80 81 int pointerarray(int* p){ 82 p[2] = 300; 83 p[3] = 400; 84 85 return 0; 86 } 6.2 multioutput-samle.c multioutput-sample > gcc -o multioutput-sample multioutput-sample.c 12

6.3 6.4 6.5 3 3 selection[3] play 9 num try: selection: reward: (39 ) 1 /******************************************************* 2 ( ) 3 *******************************************************/ 4 5 #include <stdio.h> /* */ 6 #include <stdlib.h> /* */ 7 #include "bandit.h" /* */ 8 9 double play(int num_try, int* selection, double* reward); 10 11 int main(){ 12 int num_arm, loop, arm_select, selection[3]; 13 double total_reward, reward[3]; 14 15 init_bandit(); /* */ 16 17 num_arm = get_arm_num();/* */ 18 printf(" %d \n",num_arm); 19 20 /* (3 ) */ 21 for(loop=0 ; loop<3 ; loop++){ 22 printf(" [1-%d]:",num_arm); 23 scanf("%d", &arm_select); 24 selection[loop] = arm_select; 25 } 26 27 total_reward = play(3, selection, reward); 28 13

29 /* */ 30 for(loop=0 ; loop<3 ; loop++){ 31 printf("%d : =%lf\n",loop+1,reward[loop]); 32 } 33 printf(" :%lf\n",total_reward); 34 35 return 0; 36 } 37 38 double play(int num_try, int* selection, double* reward){ 39 40 } 7 [1] [2] [3] 14