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

Size: px
Start display at page:

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

Transcription

1 C C main() 1 FORTRAN C main() main main() main() 1 return 1

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

3 1 2 C 1: 1 #include <s t d i o. h> 2 3 double b i g g e r ( double a, double b ) ; /* */ 4 5 /* ===================================================================== */ 6 /* */ 7 /* ===================================================================== */ 8 int main ( void ){ 9 double x, y, z ; x =2.5; 12 y = ; z=b i g g e r ( x, y ) ; p r i n t f ( % f \n, z ) ; return 0 ; /* ===================================================================== */ 22 /* */ 23 /* ===================================================================== */ 24 double b i g g e r ( double a, double b ){ 25 double big ; i f ( a<b ){ 28 big = b ; 29 else { 30 big = a ; return big ;

4 main 関数始め x 2.5 y bigger 関数始め UNIX bigger の呼び出し z 戻り値 a < b yes no 0 を戻り値として返す 戻り値は big の値 big b big a z の表示 bigger 関数終り main 関数終り OS(UNIX) の守備範囲 C 言語プログラム 2: windows ( ) ( ) 2 ( ) C 2 module: 4

5 a[] 100 b[] 2 (18 ) p.449 srand 2: 1 #include <s t d i o. h> 2 #include <s t d l i b. h> 3 #include <time. h> 4 5 int main ( void ){ 6 int a [ 1 0 ], b [ ], max a, max b, i ; 7 8 srand ( ( unsigned int ) time (NULL) ) ; /* */ 9 10 for ( i =0; i <10; i ++) a [ i ]= rand ( ) ; /* a[] */ 11 for ( i =0; i <100; i ++) b [ i ]= rand ( ) ; /* b[] */ /* ---- a[] */ 14 max a=a [ 0 ] ; 15 for ( i =1; i <10; i ++){ 16 i f ( max a<a [ i ] ) max a=a [ i ] ; /* ---- b[] */ 20 max b=b [ 0 ] ; 21 for ( i =1; i <100; i ++){ 22 i f ( max b<b [ i ] ) max b=b [ i ] ; p r i n t f ( max a=%d\n, max a ) ; /* */ 26 p r i n t f ( max b=%d\n, max b ) ; return 0 ; : 1 #include <s t d i o. h> 2 #include <s t d l i b. h> 3 #include <time. h> 4 5 int find max ( int n, int i x [ ] ) ; /* */ 6 5

6 7 /* ========================================================================= */ 8 /* main */ 9 /* ========================================================================= */ 10 int main ( void ){ 11 int a [ 1 0 ], b [ ], max a, max b, i ; srand ( ( unsigned int ) time (NULL) ) ; /* */ for ( i =0; i <10; i ++) a [ i ]= rand ( ) ; /* a[] */ 16 for ( i =0; i <100; i ++) b [ i ]= rand ( ) ; /* b[] */ max a=find max ( 1 0, a ) ; 19 max b=find max ( 1 0 0, b ) ; p r i n t f ( max a=%d\n, max a ) ; /* */ 22 p r i n t f ( max b=%d\n, max b ) ; return 0 ; /* ========================================================================= */ 28 /* */ 29 /* ========================================================================= */ 30 int find max ( int n, int i x [ ] ) { 31 int i, max ; /* ---- a[] */ 34 max=i x [ 0 ] ; 35 for ( i =1; i <n ; i ++){ 36 i f (max<i x [ i ] ) max=i x [ i ] ; return max ; : 1 #include <s t d i o. h> 2 #include <s t d l i b. h> 3 #include <time. h> 4 5 /* */ 6 void make data ( int nx, int i x [ ], int ny, int i y [ ] ) ; 7 int find max ( int n, int i x [ ] ) ; 8 void p r i n t r e s u l t s ( int a, int b ) ; 9 10 /* ========================================================================= */ 11 /* main */ 12 /* ========================================================================= */ 13 int main ( void ){ 14 int a [ 1 0 ], b [ ], max a, max b ;

7 17 make data ( 1 0, a, 100, b ) ; /* */ max a=find max ( 1 0, a ) ; /* */ 20 max b=find max ( 1 0 0, b ) ; p r i n t r e s u l t s ( max a, max b ) ; /* */ return 0 ; /* ========================================================================= */ 29 /* */ 30 /* ========================================================================= */ 31 void make data ( int nx, int i x [ ], int ny, int i y [ ] ) { 32 int i ; srand ( ( unsigned int ) time (NULL) ) ; /* */ for ( i =0; i <nx ; i ++) i x [ i ]= rand ( ) ; 37 for ( i =0; i <ny ; i ++) i y [ i ]= rand ( ) ; /* ========================================================================= */ 43 /* */ 44 /* ========================================================================= */ 45 int find max ( int n, int i x [ ] ) { 46 int i, max ; /* ---- a[] */ 49 max=i x [ 0 ] ; 50 for ( i =1; i <n ; i ++){ 51 i f (max<i x [ i ] ) max=i x [ i ] ; return max ; /* ========================================================================= */ 59 /* */ 60 /* ========================================================================= */ 61 void p r i n t r e s u l t s ( int a, int b ){ p r i n t f ( max a=%d\n, a ) ; 64 p r i n t f ( max b=%d\n, b ) ;

8 3 3 (Call: ) ( [?] 5.3) (1) (2) (3) ( ) return return ; 3 C 8

9 #include <stdio.h> メイン関数 戻り値の型名 hogehoge( 引数の型名前 ); 戻り値の型名 fugafuga( 引数の型名前 ); int main(void) { 文 a = hogehoge( 実引数 ); プロトタイプ宣言 関数の呼び出し return 0; 戻り値の型名 hogehoge( 引数の型仮引数名 ){ 関数 hegehoge 文 b=fugafuga( 実引数 ); return 式 ; 関数の呼び出し 関数の定義 関数 fugafuga 戻り値の型名 fugafuga( 引数の型仮引数名 ){ 文 return 式 ; 関数の定義 3: 9

10 3.2 main ( ) (scope: ) printf("%f", hogehoge); 3 { fuga at main = 222 hoge at main = 111 foo at test = 333 foo at test = 111 bar at for loop = 444 bar at for loop = if 10

11 #include <stdio.h> void test(void); // プロトタイプ宣言 int hoge=111; グローバル変数 //=============================================== // メイン関数 //=============================================== int main(void){ int i; int fuga=222; ローカル変数 printf("fuga at main = %d\n", fuga); printf("hoge at main = %d\n", hoge); test(); for(i=1; i<3; i++){ int bar=444; printf("bar at for loop = %d\n", bar); return 0;; ブロック内宣言の変数 //=============================================== // test ユーザー定義関数 //=============================================== void test(void){ int foo=333; ローカル変数 printf("foo at test = %d\n", foo); printf("foo at test = %d\n", hoge); ブロック内宣言の変数 bar の有効範囲 ローカル変数 i, fuga の有効範囲 ローカル変数 foo の有効範囲 グローバル変数 hoge の有効範囲 4: ( ) 4.2? 11

12 C hogehoge hogehoge?? (1) (2) (3) 5 (p.214) ( ) ( ) 3 2 ( ) 5.1 (p.214) [ 1] main [ ] sin cos tan main 0 360[ ] 1 #include <math.h> math.h sin(a),cos(a),tan(a) [ ] 12

13 -lm C hogehoge.c fugafuga gcc -lm -o fugafuga hogehoge.c [ 2] 5 i,j 5: 1 #include <s t d i o. h> 2 3 void swap ( int i, int j ) ; /* */ 4 5 /* ===================================================================== */ 6 /* */ 7 /* ===================================================================== */ 8 int main ( void ){ 9 int a=2, b=3; p r i n t f ( a=%d b=%d\n, a, b ) ; swap ( a, b ) ; p r i n t f ( a=%d b=%d\n, a, b ) ; return 0 ; /* ===================================================================== */ 21 /* s w a p */ 22 /* ===================================================================== */ 23 void swap ( int i, int j ){ 24 int temp ; temp = i ; 27 i=j ; 28 j=temp ; (p.216) [ 3] 6 i,j 6: 1 #include <s t d i o. h> 2 3 void swap ( int i, int j ) ; /* */ 4 5 /* ===================================================================== */ 6 /* */ 7 /* ===================================================================== */ 13

14 8 int main ( void ){ 9 int a=2, b=3; p r i n t f ( a=%d b=%d\n, a, b ) ; swap(&a, &b ) ; p r i n t f ( a=%d b=%d\n, a, b ) ; return 0 ; /* ===================================================================== */ 21 /* s w a p */ 22 /* ===================================================================== */ 23 void swap ( int i, int j ){ 24 int temp ; temp = i ; 27 i = j ; 28 j=temp ; (p.218) [ 4] (p.220) [ 5] (p.222) 14

15 6.1 1 (p.222) [ 6] f(x) = x x3 6 + x5 120 x x = 0 x = ? n pow P.437 pow #include <math.h> -lm 6.2 (p.223) [ 7] sin 2θ 2 sin θ cos θ [ ] void keisan(double theta, double *s1, double *s2); 7 (p.228) [ 8] 6 8 main (p.228) 15

16 9 9.1 [ 1] ( ) [1] 11 (pp ) 3 3 [ 2] ( ) 2 2 [ 3] ( ) 3 s = a + b + c 2 S = s(s a)(s b)(s c) S (a, b, c) -1 [ 4] ( ) f(x) = x + 3 x x2 10x + x sin(x) + x x 10 (1) x 10 4 : x x max f max x [ 5] ( ) A = [ 6] ( ) C f(x) = 1 x2 2! + x4 4! x4 6! + x8 8! x10 10! + N ( 1) k = (2k)! x2k k=0 16

17 N = 1, 3, 5, 7 f(x) cos(x) [ π, π] [ 7] ( )[ 2] [ 3] [ 8] ( )( ) [1] [ 9] ( ) AM 8:45 A4 1 5E 2 17

18 A 0 C C rand() rand() a[i] for(i=0; i<ndata; i++){ a[i]=rand(); rand() 6 time() srand() ( ) srand((unsigned int)time(null)); 1 time (unsigned int) time() NULL rand() srand() time() rand() srand() stdlib.h time() time.h a[i] 1024 #include <stdlib.h> #include <time.h> int main(void){ int a[1024], i; srand((unsigned int)time(null)); for(i=0; i<1024; i++){ a[i]=rand(); return 0; seed( ) 18

19 [1]. C.,

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

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

[ 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] 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: 005 9 7 1 1.1 1 Hello World!! 5 p r i n t f ( H e l l o World!! \ n ) ; 7 return 0 ; 8 } 1: 1 [ ] Hello World!! from Akita National College of Technology. 1 : 5 p r i n t f ( H e l l o World!! \ n ) ;

More information

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h> 2007 12 5 1 2 2.1 ( ) 1 1: 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 #define H WIN 400 // 8 #define W WIN 300 // 9

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

講習No.12

講習No.12 前回までの関数のまとめ 関数は main() 関数または他の関数から呼び出されて実行される. 関数を呼び出す側の実引数の値が関数内の仮引数 ( 変数 ) にコピーされる. 関数内で定義した変数は, 関数の外からは用いることができない ( ローカル変数 ). 一般に関数内で仮引数を変化しても, 呼び出し側の変数は変化しない ( 値渡し ). 関数内で求めた値は return 文によって関数値として呼び出し側に戻される.

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

[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

gengo1-10

gengo1-10 関数 C 言語では 関数を組み合わせてプログラムを構成する pritnf(), scanf() などは 処理系があらかじめ備えている標準ライブラリ関数 math.h で定義されている算術関数も標準ライブラリ関数の 1 つ データを与えて それに基づき何か動作をおこなうものが関数 数学の関数 y = f(x) のイメージ f(x) x を与える f(x) を計算して返す f(x) はある意味ブラックボックス

More information

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

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

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

関数の動作 / printhw(); 7 printf(" n"); printhw(); printf("############ n"); 4 printhw(); 5 関数の作り方 ( 関数名 ) 戻り値 ( 後述 ) void である. 関数名 (

関数の動作 / printhw(); 7 printf( n); printhw(); printf(############ n); 4 printhw(); 5 関数の作り方 ( 関数名 ) 戻り値 ( 後述 ) void である. 関数名 ( 概要 プログラミング 関数 http://www.ns.kogakuin.ac.jp/~ct40/progc/ A- 関数の作り方を学ぶ 関数名, 引数, 戻り値 プログラミング で最も重要な事項 関数 プログラミング で最も重要な事項 制御 (for, if) プログラミング で最も重要な事項 ポインタ A- 関数名 引数 戻り値 E- E-4 関数の概要 0/ 関数とは, 複数の処理をひとまとめにしたもの.

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

数値計算

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

More information

Microsoft Word - no11.docx

Microsoft Word - no11.docx 3. 関数 3.1 関数関数は数学の関数と同じようなイメージを持つと良いでしょう 例えば三角関数の様に一つの実数値 ( 角度 ) から値を求めますし 対数関数の様に二つの値から一つの値を出すものもあるでしょう これをイメージしてもらえば結構です つまり 何らかの値を渡し それをもとに何かの作業や計算を行い その結果を返すのが関数です C 言語の関数も基本は同じです 0 cos 1 cos(0) =

More information

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裱£²²ó ¡Ý½ÉÂꣲ¤Î²òÀ⡤±é½¬£²¡Ý

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裱£²²ó  ¡Ý½ÉÂꣲ¤Î²òÀ⡤±é½¬£²¡Ý (2018) 2018 7 5 f(x) [ 1, 1] 3 3 1 3 f(x) dx c i f(x i ) 1 0 i=1 = 5 ) ( ) 3 ( 9 f + 8 5 9 f(0) + 5 3 9 f 5 1 1 + sin(x) θ ( 1 θ dx = tan 1 + sin x 2 π ) + 1 4 1 3 [a, b] f a, b double G3(double (*f)(),

More information

70 : 20 : A B (20 ) (30 ) 50 1

70 : 20 : A B (20 ) (30 ) 50 1 70 : 0 : A B (0 ) (30 ) 50 1 1 4 1.1................................................ 5 1. A............................................... 6 1.3 B............................................... 7 8.1 A...............................................

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

(search: ) [1] ( ) 2 (linear search) (sequential search) 1

(search: ) [1] ( ) 2 (linear search) (sequential search) 1 2005 11 14 1 1.1 2 1.2 (search:) [1] () 2 (linear search) (sequential search) 1 2.1 2.1.1 List 2-1(p.37) 1 1 13 n

More information

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

/*Source.cpp*/ #include<stdio.h> //printf はここでインクルードして初めて使えるようになる // ここで関数 average を定義 3 つの整数の平均値を返す double 型の関数です double average(int a,int b,int c){ ソフトゼミ A 第 6 回 関数 プログラムは関数の組み合わせでできています 今までのゼミAでも printf や scanf など様々な関数を使ってきましたが なんと関数は自分で作ることもできるのです!! 今日は自作関数を中心に扱っていきます ゲーム制作でも自作関数は避けては通れないので頑張りましょう そもそもまず 関数とは 基本的には 受け取った値に関数によって定められた操作をして その結果の値を返す

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

1 (1) ( i ) 60 (ii) 75 (iii) 315 (2) π ( i ) (ii) π (iii) 7 12 π ( (3) r, AOB = θ 0 < θ < π ) OAB A 2 OB P ( AB ) < ( AP ) (4) 0 < θ < π 2 sin θ

1 (1) ( i ) 60 (ii) 75 (iii) 315 (2) π ( i ) (ii) π (iii) 7 12 π ( (3) r, AOB = θ 0 < θ < π ) OAB A 2 OB P ( AB ) < ( AP ) (4) 0 < θ < π 2 sin θ 1 (1) ( i ) 60 (ii) 75 (iii) 15 () ( i ) (ii) 4 (iii) 7 1 ( () r, AOB = θ 0 < θ < ) OAB A OB P ( AB ) < ( AP ) (4) 0 < θ < sin θ < θ < tan θ 0 x, 0 y (1) sin x = sin y (x, y) () cos x cos y (x, y) 1 c

More information

C ( ) C ( ) C C C C C 1 Fortran Character*72 name Integer age Real income 3 1 C mandata mandata ( ) name age income mandata ( ) mandat

C ( ) C ( ) C C C C C 1 Fortran Character*72 name Integer age Real income 3 1 C mandata mandata ( ) name age income mandata ( ) mandat C () 14 5 23 C () C C C C C 1 Fortran Character*72 name Integer age Real income 3 1 C 1.1 3 7 mandata mandata () name age income mandata () mandata1 1 #include struct mandata char name[51];

More information

C

C C 1 2 1.1........................... 2 1.2........................ 2 1.3 make................................................ 3 1.4....................................... 5 1.4.1 strip................................................

More information

memo

memo 計数工学プログラミング演習 ( 第 3 回 ) 2017/04/25 DEPARTMENT OF MATHEMATICAL INFORMATICS 1 内容 ポインタの続き 引数の値渡しと参照渡し 構造体 2 ポインタで指されるメモリへのアクセス double **R; 型 R[i] と *(R+i) は同じ意味 意味 R double ** ポインタの配列 ( の先頭 ) へのポインタ R[i]

More information

6 関数 6-1 関数とは少し長いプログラムを作るようになると 同じ処理を何度も行う場面が出てくる そのたびに処 理を書いていたのでは明らかに無駄であるし プログラム全体の見通しも悪くなる そこで登場す るのが 関数 である 関数を使うことを 関数を呼び出す ともいう どのように使うのか 実際に見て

6 関数 6-1 関数とは少し長いプログラムを作るようになると 同じ処理を何度も行う場面が出てくる そのたびに処 理を書いていたのでは明らかに無駄であるし プログラム全体の見通しも悪くなる そこで登場す るのが 関数 である 関数を使うことを 関数を呼び出す ともいう どのように使うのか 実際に見て 6 関数 6-1 関数とは少し長いプログラムを作るようになると 同じ処理を何度も行う場面が出てくる そのたびに処 理を書いていたのでは明らかに無駄であるし プログラム全体の見通しも悪くなる そこで登場す るのが 関数 である 関数を使うことを 関数を呼び出す ともいう どのように使うのか 実際に見てみよう 次のプログラムは 2 つの数字のうち 大きい方を求 めるものである int max(int a,

More information

プログラミング実習I

プログラミング実習I プログラミング実習 I 05 関数 (1) 人間システム工学科井村誠孝 m.imura@kwansei.ac.jp 関数とは p.162 数学的には入力に対して出力が決まるもの C 言語では入出力が定まったひとまとまりの処理 入力や出力はあるときもないときもある main() も関数の一種 何かの仕事をこなしてくれる魔法のブラックボックス 例 : printf() 関数中で行われている処理の詳細を使う側は知らないが,

More information

(x, y) 2. OK NG1 1

(x, y) 2. OK NG1 1 12 22 1. (x, y) 2. OK NG1 1 12 22 / sample program for a Information class DATE: 2014-12-22 convert angle unit, from radian to degree / #include / for printf() / #include / for atan2()

More information

Microsoft PowerPoint pptx[読み取り専用]

Microsoft PowerPoint pptx[読み取り専用] 情報処理 Ⅱ 第 8 回 2009 年 12 月 7 日 ( 月 ) 本日学ぶこと 関数と変数 目的 関数を自分で定義し, 変数の利用方法 範囲を明示的に制限することで, 適切な機能分割 ( モジュール化, 再利用 ) を図る. してはいけないこと 問題 main 関数のみで 100 行以上のプログラム グローバル変数を駆使するプログラム プログラムを読みやすくする 保守性向上 多項式関数 f(x)

More information

θ (t) ω cos θ(t) = ( : θ, θ. ( ) ( ) ( 5) l () θ (t) = ω sin θ(t). ω := g l.. () θ (t) θ (t)θ (t) + ω θ (t) sin θ(t) =. [ ] d dt θ (t) ω cos θ(t

θ (t) ω cos θ(t) = ( : θ, θ. ( ) ( ) ( 5) l () θ (t) = ω sin θ(t). ω := g l.. () θ (t) θ (t)θ (t) + ω θ (t) sin θ(t) =. [ ] d dt θ (t) ω cos θ(t 7 8, /3/, 5// http://nalab.mind.meiji.ac.jp/~mk/labo/text/furiko/ l (, simple pendulum) m g mlθ (t) = mg sin θ(t) () θ (t) + ω sin θ(t) =, ω := ( m ) ( θ ) sin θ θ θ (t) + ω θ(t) = ( ) ( ) g l θ(t) = C

More information

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

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 C 1 / 21 C 2005 A * 1 2 1.1......................................... 2 1.2 *.......................................... 3 2 4 2.1.............................................. 4 2.2..............................................

More information

Microsoft Word - 03

Microsoft Word - 03 平成 24 年度講義 アルゴリズムとデータ構造 第 3 回変数のスコープルール 関数 担当 : 富井尚志 (tommy@ynu.ac.jp) 選択計算 ( 条件判断 ) 第 2 回 基本的制御構造 の復習 if 文 : ある条件に応じて別々の計算を行う. 式が真 (0 以外 ) であれば文 1 が実行され, 偽であれば文 2 が実行される. なお,else 以下は省略可能である. if ( 式 )

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

練習&演習問題

練習&演習問題 練習問題 ファイル入出力 練習問題 1 ファイルへのデータ出力 配列 a[ ] の値をファイル data.txt に出力するプログラムを作成しなさい #include #include /* srand(), rand() */ #include /* time() */ int main(void) { int i; double a[5];

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

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

バイオプログラミング第 1 榊原康文 佐藤健吾 慶應義塾大学理工学部生命情報学科 バイオプログラミング第 1 榊原康文 佐藤健吾 慶應義塾大学理工学部生命情報学科 ポインタ変数の扱い方 1 ポインタ変数の宣言 int *p; double *q; 2 ポインタ変数へのアドレスの代入 int *p; と宣言した時,p がポインタ変数 int x; と普通に宣言した変数に対して, p = &x; は x のアドレスのポインタ変数 p への代入 ポインタ変数の扱い方 3 間接参照 (

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

02: 変数と標準入出力

02: 変数と標準入出力 C プログラミング入門 総機 1 ( 月 1) 11: 動的メモリ確保 Linux にログインし 以下の講義ページを開いておくこと http://www-it.sci.waseda.ac.jp/ teachers/w483692/cpr1/ 2015-06-22 1 まとめ : ポインタを使った処理 内容 説明 呼び出し元の変数を書き換える第 9 回 文字列を渡す 配列を渡す 第 10 回 ファイルポインタ

More information

USB 0.6 https://duet.doshisha.ac.jp/info/index.jsp 2 ID TA DUET 24:00 DUET XXX -YY.c ( ) XXX -YY.txt() XXX ID 3 YY ID 5 () #define StudentID 231

USB 0.6 https://duet.doshisha.ac.jp/info/index.jsp 2 ID TA DUET 24:00 DUET XXX -YY.c ( ) XXX -YY.txt() XXX ID 3 YY ID 5 () #define StudentID 231 0 0.1 ANSI-C 0.2 web http://www1.doshisha.ac.jp/ kibuki/programming/resume p.html 0.3 2012 1 9/28 0 [ 01] 2 10/5 1 C 2 3 10/12 10 1 2 [ 02] 4 10/19 3 5 10/26 3 [ 03] 6 11/2 3 [ 04] 7 11/9 8 11/16 4 9 11/30

More information

memo

memo 数理情報工学演習第一 C プログラミング演習 ( 第 5 回 ) 2015/05/11 DEPARTMENT OF MATHEMATICAL INFORMATICS 1 今日の内容 : プロトタイプ宣言 ヘッダーファイル, プログラムの分割 課題 : 疎行列 2 プロトタイプ宣言 3 C 言語では, 関数や変数は使用する前 ( ソースの上のほう ) に定義されている必要がある. double sub(int

More information

(1) プログラムの開始場所はいつでも main( ) メソッドから始まる 順番に実行され add( a,b) が実行される これは メソッドを呼び出す ともいう (2)add( ) メソッドに実行が移る この際 add( ) メソッド呼び出し時の a と b の値がそれぞれ add( ) メソッド

(1) プログラムの開始場所はいつでも main( ) メソッドから始まる 順番に実行され add( a,b) が実行される これは メソッドを呼び出す ともいう (2)add( ) メソッドに実行が移る この際 add( ) メソッド呼び出し時の a と b の値がそれぞれ add( ) メソッド メソッド ( 教科書第 7 章 p.221~p.239) ここまでには文字列を表示する System.out.print() やキーボードから整数を入力する stdin.nextint() などを用いてプログラムを作成してきた これらはメソッドと呼ばれるプログラムを構成する部品である メソッドとは Java や C++ などのオブジェクト指向プログラミング言語で利用されている概念であり 他の言語での関数やサブルーチンに相当するが

More information

I 2 tutimura/ I 2 p.1/??

I 2   tutimura/ I 2 p.1/?? I 2 tutimura@mist.i.u-tokyo.ac.jp http://www.misojiro.t.u-tokyo.ac.jp/ tutimura/ 2002 4 25 I 2 p.1/?? / / Makefile I 2 p.2/?? Makefile make GNU make I 2 p.3/?? Makefile L A T E X I 2 p.4/?? core (1) gcc,

More information

, x R, f (x),, df dx : R R,, f : R R, f(x) ( ).,, f (a) d f dx (a), f (a) d3 f dx 3 (a),, f (n) (a) dn f dx n (a), f d f dx, f d3 f dx 3,, f (n) dn f

, x R, f (x),, df dx : R R,, f : R R, f(x) ( ).,, f (a) d f dx (a), f (a) d3 f dx 3 (a),, f (n) (a) dn f dx n (a), f d f dx, f d3 f dx 3,, f (n) dn f ,,,,.,,,. R f : R R R a R, f(a + ) f(a) lim 0 (), df dx (a) f (a), f(x) x a, f (a), f(x) x a ( ). y f(a + ) y f(x) f(a+) f(a) f(a + ) f(a) f(a) x a 0 a a + x 0 a a + x y y f(x) 0 : 0, f(a+) f(a)., f(x)

More information

Microsoft Word - no15.docx

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

More information

Microsoft PowerPoint - 09.pptx

Microsoft PowerPoint - 09.pptx 情報処理 Ⅱ 第 9 回 2014 年 12 月 22 日 ( 月 ) 関数とは なぜ関数 関数の分類 自作関数 : 自分で定義する. ユーザ関数 ユーザ定義関数 などともいう. 本日のテーマ ライブラリ関数 : 出来合いのもの.printf など. なぜ関数を定義するのか? 処理を共通化 ( 一般化 ) する プログラムの見通しをよくする 機能分割 ( モジュール化, 再利用 ) 責任 ( あるいは不具合の発生源

More information

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

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 << C++ C C++ 1 C++ C++ C C++ C C++? C C++ C *.c *.cpp C cpp VC C++ 2 C++ C++ C++ [1], C++,,1999 [2],,,2001 [3], ( )( ),,2001 [4] B.W. /D.M.,, C,,1989 C Web [5], http://kumei.ne.jp/c_lang/ 3 Hello World Hello

More information

PowerPoint プレゼンテーション

PowerPoint プレゼンテーション プログラミング初級 第 13 回 2017 年 7 月 10 日 標準ライブラリ関数 1 標準ライブラリ関数とは 関数には (1) 自分で作る関数 (2) はじめから用意されている関数特に C 言語用用意されているもの : 標準ライブラリ関数 文字列の代入文字列の長さを求める文字列の比較文字列の連結 strcpy strlen strcmp strcat 2 文字列の操作 - 具体例を通して (141

More information

joho09.ppt

joho09.ppt s M B e E s: (+ or -) M: B: (=2) e: E: ax 2 + bx + c = 0 y = ax 2 + bx + c x a, b y +/- [a, b] a, b y (a+b) / 2 1-2 1-3 x 1 A a, b y 1. 2. a, b 3. for Loop (b-a)/ 4. y=a*x*x + b*x + c 5. y==0.0 y (y2)

More information

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

関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include <stdiu.h> #define InFile data.txt #define OutFile surted.txt #def C プログラミング演習 1( 再 ) 6 講義では C プログラミングの基本を学び 演習では やや実践的なプログラミングを通して学ぶ 関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include #define InFile "data.txt" #define OutFile "surted.txt"

More information

卒 業 研 究 報 告.PDF

卒 業 研 究 報 告.PDF C 13 2 9 1 1-1. 1-2. 2 2-1. 2-2. 2-3. 2-4. 3 3-1. 3-2. 3-3. 3-4. 3-5. 3-5-1. 3-5-2. 3-6. 3-6-1. 3-6-2. 4 5 6 7-1 - 1 1 1-1. 1-2. ++ Lisp Pascal Java Purl HTML Windows - 2-2 2 2-1. 1972 D.M. (Dennis M Ritchie)

More information

プログラミング実習I

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

More information

02: 変数と標準入出力

02: 変数と標準入出力 C プログラミング入門 基幹 2 ( 月 4) 11: 動的メモリ確保 Linux にログインし 以下の講義ページを開いておくこと http://www-it.sci.waseda.ac.jp/ teachers/w483692/cpr1/ 2014-06-22 1 まとめ : ポインタを使った処理 内容 説明 呼び出し元の変数を書き換える第 9 回 文字列を渡す 配列を渡す 第 10 回 ファイルポインタ

More information

<4D F736F F D20438CBE8CEA8D758DC03389F0939A82C282AB2E646F63>

<4D F736F F D20438CBE8CEA8D758DC03389F0939A82C282AB2E646F63> C 言語講座第 3 回 キャスト ( 型変換 ) 強制的に式の型を変換する ( 変換したい型名 ) 変換元で記述する int num_a = 10, num_b = 3; float result1, result2; // 結果格納用 // 計算用 result1 = num_a / num_b; // 通常のint/int 割り算 result2 = (float)num_a / num_b;//

More information

file:///D|/C言語の擬似クラス.txt

file:///D|/C言語の擬似クラス.txt 愛知障害者職業能力開発校 システム設計科 修了研究発表会報告書 題名 : C 言語の擬似クラス あらまし : C 言語でクラスを作れるという噂の真偽を確かめるために思考錯誤した まえがき : VC++ や Java その他オブジェクト指向の言語にはクラスが存在して クラスはオブジェクトの設計図である 手法 : C++ のクラスを解析して C++ のクラスを作成して C 言語に翻訳する class struct

More information

02: 変数と標準入出力

02: 変数と標準入出力 C プログラミング入門 基幹 7 ( 水 5) 09: ポインタ 文字列 Linux にログインし 以下の講義ページを開いておくこと http://www-it.sci.waseda.ac.jp/teachers/w 483692/CPR/ 207-06-4 関数できなかったこと 2 配列を引数として渡す, 戻り値として返す 文字列を扱う 呼び出し元の変数を直接書き換える 例 : 2 つの変数の値を入れ替える関数

More information

講習No.10

講習No.10 2 次元配列 復習 float d[3][4]; 2 次元配列 d[i][j] 2 つのインデックス i と j でデータが指定される 縦が 3 行横が 4 列の float 型の表 4 列 横のインデックスは 3 まで j = 0 j = 1 j = 2 j = 3 3 行 i = 0 i = 1 i = 2 d[0][0] d[0][1] d[0][2] d[0][3] d[1][0] d[1][1]

More information

情報処理 Ⅱ 2007 年 11 月 26 日 ( 月 )

情報処理 Ⅱ 2007 年 11 月 26 日 ( 月 ) 情報処理 Ⅱ 2007 年 11 月 26 日 ( 月 ) 本日学ぶこと 関数と変数 目的 関数を自分で定義し, 変数の利用方法 範囲を明示的に制限することで, 適切な機能分割 ( モジュール化, 再利用 ) を図る. してはいけないこと main 関数のみで 100 行以上のプログラム グローバル変数を駆使するプログラム プログラムを読みやすくする 保守性向上 入 p.109 2 関数 (Function)

More information

Microsoft PowerPoint - prog07.ppt

Microsoft PowerPoint - prog07.ppt プログラミング言語 2 第 07 回 (2007 年 06 月 18 日 ) 1 今日の配布物 片面の用紙 1 枚 今日の課題が書かれています 本日の出欠を兼ねています 2/32 1 今日やること http://www.tnlab.ice.uec.ac.jp/~s-okubo/class/language/ にアクセスすると 教材があります 2007 年 06 月 18 日分と書いてある部分が 本日の教材です

More information

スライド 1

スライド 1 数値解析 2019 年度前期第 13 週 [7 月 11 日 ] 静岡大学創造科学技術大学院情報科学専攻工学部機械工学科計測情報講座 三浦憲二郎 講義アウトライン [7 月 11 日 ] 関数近似と補間 最小 2 乗近似による関数近似 ラグランジュ補間 T.Kanai, U.Tokyo 関数近似 p.116 複雑な関数を簡単な関数で近似する 関数近似 閉区間 [a,b] で定義された関数 f(x)

More information

02: 変数と標準入出力

02: 変数と標準入出力 C プログラミング入門 基幹 2 ( 月 4) 09: ポインタ 文字列 Linux にログインし 以下の講義ページを開いておくこと http://www-it.sci.waseda.ac.jp/ teachers/w483692/cpr1/ 2014-06-09 1 関数できなかったこと 配列を引数として渡す, 戻り値として返す 文字列を扱う 呼び出し元の変数を直接書き換える 例 : 2 つの変数の値を入れ替える関数

More information

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

Microsoft PowerPoint - 10.ppt [互換モード] 第 10 回関数と再帰 1 今回の目標 再帰的な考え方に慣れる C 言語における再帰関数を理解する 階乗を求める再帰的な関数を作成し その関数を利用するプログラムを作成する 2 階乗 n! の 2 つの数学的表現 (1) 繰り返しによる表現 n! = 1 2 i n n = ii i= 1 ( n 1 のとき ) ( なお 0!=1) (2) 漸化式による表現 n! = 1 n = 0のとき n (

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

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

Cプログラミング1(再) 第2回 C プログラミング 1( 再 ) 第 2 回 講義では Cプログラミングの基本を学び演習では やや実践的なプログラミングを通して学ぶ 1 前回のレポートから 前回の宿題 数あてゲーム の説明において 次のように書いていたものがいた : これはコンピュータがランダムに設定した数字を人間が当てるゲームである この説明でどこかおかしなところはないだろうか? 2 コンピュータの用語と日常的な用語の違い 物理において

More information

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

関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include <stdio.h> #define InFile data.txt #define OutFile sorted.txt #def C プログラミング演習 1( 再 ) 6 講義では C プログラミングの基本を学び 演習では やや実践的なプログラミングを通して学ぶ 関数の呼び出し ( 選択ソート ) 選択ソートのプログラム (findminvalue, findandreplace ができているとする ) #include #define InFile "data.txt" #define OutFile "sorted.txt"

More information

概要 プログラミング論 変数のスコープ, 記憶クラス. メモリ動的確保. 変数のスコープ 重要. おそらく簡単. 記憶クラス 自動変数 (auto) と静的変数 (static). スコープほどではないが重要.

概要 プログラミング論 変数のスコープ, 記憶クラス. メモリ動的確保. 変数のスコープ 重要. おそらく簡単. 記憶クラス 自動変数 (auto) と静的変数 (static). スコープほどではないが重要. 概要 プログラミング論 変数のスコープ, 記憶クラス. メモリ動的確保. 変数のスコープ 重要. おそらく簡単. 記憶クラス 自動変数 (auto) と静的変数 (static). スコープほどではないが重要. http://www.ns.kogakuin.ac.jp/~ct13140/progc/ C-2 ブロック 変数のスコープ C 言語では, から をブロックという. for( ) if( )

More information

2004 2005 2 2 1G01P038-0 1 2 1.1.............................. 2 1.2......................... 2 1.3......................... 3 2 4 2.1............................ 4 2.2....................... 4 2.3.......................

More information

12 15 / sample program for a Information class DATE: heron s formula / #include <stdio.h> / for printf() / #include <math.h> / for sqrt() /

12 15 / sample program for a Information class DATE: heron s formula / #include <stdio.h> / for printf() / #include <math.h> / for sqrt() / 12 15 / sample program for a Information class DATE: 2014-12-15 heron s formula / #include / for printf() / #include / for sqrt() / double heron(double, double, double); int main(void)

More information

no35.dvi

no35.dvi p.16 1 sin x, cos x, tan x a x a, a>0, a 1 log a x a III 2 II 2 III III [3, p.36] [6] 2 [3, p.16] sin x sin x lim =1 ( ) [3, p.42] x 0 x ( ) sin x e [3, p.42] III [3, p.42] 3 3.1 5 8 *1 [5, pp.48 49] sin

More information

6 6.1 sound_wav_files flu00.wav.wav 44.1 khz 1/44100 spwave Text with Time spwave t T = N t N 44.1 khz t = 1 sec j t f j {f 0, f 1, f 2,, f N 1

6 6.1 sound_wav_files flu00.wav.wav 44.1 khz 1/44100 spwave Text with Time spwave t T = N t N 44.1 khz t = 1 sec j t f j {f 0, f 1, f 2,, f N 1 6 6.1 sound_wav_files flu00.wav.wav 44.1 khz 1/44100 spwave Text with Time spwave t T = t 44.1 khz t = 1 sec 44100 j t f j {f 0, f 1, f 2,, f 1 6.2 T {f 0, f 1, f 2,, f 1 T ft) f j = fj t) j = 0, 1, 2,,

More information

02: 変数と標準入出力

02: 変数と標準入出力 C プログラミング入門 基幹 7 ( 水 5) 11: 動的メモリ確保 Linux にログインし 以下の講義ページを開いておくこと http://www-it.sci.waseda.ac.jp/ teachers/w483692/cpr1/ 2016-06-22 1 まとめ : ポインタを使った処理 内容呼び出し元の変数を書き換える文字列を渡す 配列を渡すファイルポインタ複数の値を返す大きな領域を確保する

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

p = 1, 2, cos 2n + p)πj = cos 2nπj 2n + p)πj, sin = sin 2nπj 7.1) f j = a ) 0 + a p + a n+p cos 2nπj p=1 p=0 1 + ) b n+p p=0 sin 2nπj 1 2 a 0 +

p = 1, 2, cos 2n + p)πj = cos 2nπj 2n + p)πj, sin = sin 2nπj 7.1) f j = a ) 0 + a p + a n+p cos 2nπj p=1 p=0 1 + ) b n+p p=0 sin 2nπj 1 2 a 0 + 7 7.1 sound_wav_files flu00.wav.wav 44.1 khz 1/44100 spwave Text with Time spwave T > 0 t 44.1 khz t = 1 44100 j t f j {f 0, f 1, f 2,, f 1 = T t 7.2 T {f 0, f 1, f 2,, f 1 T ft) f j = fj t) j = 0, 1,

More information

PowerPoint Presentation

PowerPoint Presentation 第 7 回文字列数学関数ファイルの入出力 芝浦工業大学情報工学科青木義満 今回の講義内容 文字列 文字列の配列の扱い 関数への受け渡し 数学関数の利用 平方根, べき乗, 三角関数など ファイル入出力 文字列とは? (p.0) 文字列リテラル 文字 つつ : A, B, 複数の文字の並び= 文字列 puts( ぷろぐらみんぐ入門 ); で囲まれた部分 = 文字列リテラルという 文字列リテラルとナル文字

More information

のプログラムはそのままでは 人間は理解できても コンピュータは理解できません 皆さんが作るプログラムはソースプログラム ( ソースファイル ) と呼ばれます C 言語では *.c という形式にファイルで作成します そのソースプログラムをコンピュータが理解できるようなデータ形式に変換することをコンパイ

のプログラムはそのままでは 人間は理解できても コンピュータは理解できません 皆さんが作るプログラムはソースプログラム ( ソースファイル ) と呼ばれます C 言語では *.c という形式にファイルで作成します そのソースプログラムをコンピュータが理解できるようなデータ形式に変換することをコンパイ 0. レポートの書き方表紙を付ける. コンピュータプログラミング入門 (x)(xは回), 実習日, 学籍番号, 氏名を記入すること. プログラムのアルゴリズムと実行結果, プログラム自体を付けること.1 つにまとめてホッチキス止めして提出すること. 以上を満たさないレポートは受け取らない. コンパイラとテキストエディタのインストール Windows ユーザ : gcc コンパイラ Cygwin インストール

More information

£Ã¥×¥í¥°¥é¥ß¥ó¥°(2018) - Âè11²ó – ½ÉÂꣲ¤Î²òÀ⡤±é½¬£² –

£Ã¥×¥í¥°¥é¥ß¥ó¥°(2018) - Âè11²ó – ½ÉÂꣲ¤Î²òÀ⡤±é½¬£² – (2018) 11 2018 12 13 2 g v dv x dt = bv x, dv y dt = g bv y (1) b v 0 θ x(t) = v 0 cos θ ( 1 e bt) (2) b y(t) = 1 ( v 0 sin θ + g ) ( 1 e bt) g b b b t (3) 11 ( ) p14 2 1 y 4 t m y > 0 y < 0 t m1 h = 0001

More information

コンピュータ概論

コンピュータ概論 4.1 For Check Point 1. For 2. 4.1.1 For (For) For = To Step (Next) 4.1.1 Next 4.1.1 4.1.2 1 i 10 For Next Cells(i,1) Cells(1, 1) Cells(2, 1) Cells(10, 1) 4.1.2 50 1. 2 1 10 3. 0 360 10 sin() 4.1.2 For

More information

資料

資料 PC PC C VMwareをインストールする Tips: VmwareFusion *.vmx vhv.enable = TRUE Tips: Windows Hyper-V -rwxr-xr-x 1 masakazu staff 8552 7 29 13:18 a.out* -rw------- 1 masakazu staff 8552 7 29

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

kiso2-09.key

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

More information

4 4 4 a b c d a b A c d A a da ad bce O E O n A n O ad bc a d n A n O 5 {a n } S n a k n a n + k S n a a n+ S n n S n n log x x {xy } x, y x + y 7 fx

4 4 4 a b c d a b A c d A a da ad bce O E O n A n O ad bc a d n A n O 5 {a n } S n a k n a n + k S n a a n+ S n n S n n log x x {xy } x, y x + y 7 fx 4 4 5 4 I II III A B C, 5 7 I II A B,, 8, 9 I II A B O A,, Bb, b, Cc, c, c b c b b c c c OA BC P BC OP BC P AP BC n f n x xn e x! e n! n f n x f n x f n x f k x k 4 e > f n x dx k k! fx sin x cos x tan

More information

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

Taro-リストⅢ(公開版).jtd リスト Ⅲ 0. 目次 2. 基本的な操作 2. 1 リストから要素の削除 2. 2 リストの複写 2. 3 リストの連結 2. 4 問題 問題 1 問題 2-1 - 2. 基本的な操作 2. 1 リストから要素の削除 まず 一般的な処理を書き つぎに 特別な処理を書く 一般的な処理は 処理 1 : リスト中に 削除するデータを見つけ 削除する場合への対応 特別な処理は 処理 2 : 先頭のデータを削除する場合への対応

More information

Prog1_15th

Prog1_15th 2012 年 7 月 26 日 ( 木 ) 実施構造体と typedef typedef 宣言によって,struct 構造体タグ名という表記を再定義し, データ型名のように扱うことができる 構文は typedef struct 構造体タグ名 再定義名 ; となり, この場合の構造体変数の宣言は, 再定義名を用いて行うことができる なお, ここでは 構造体タグ名は省略可能である 構造体を指すポインタ

More information

memo

memo 計数工学プログラミング演習 ( 第 3 回 ) 2016/04/26 DEPARTMENT OF MATHEMATICAL INFORMATICS 1 内容 ポインタ malloc 構造体 2 ポインタ あるメモリ領域 ( アドレス ) を代入できる変数 型は一致している必要がある 定義時には値は不定 ( 何も指していない ) 実際にはどこかのメモリを指しているので, #include

More information

1.ppt

1.ppt /* * Program name: hello.c */ #include int main() { printf( hello, world\n ); return 0; /* * Program name: Hello.java */ import java.io.*; class Hello { public static void main(string[] arg)

More information

関数の中で宣言された変数の有効範囲はその関数の中だけです さっきの rectangle _s で宣言されている変数 s は他の関数では使用できません ( 別の関数で同じ名前の変数を宣言することはできますが 全く別の変数として扱われます このように ある関数の中で宣言されている変数のことをその関数の

関数の中で宣言された変数の有効範囲はその関数の中だけです さっきの rectangle _s で宣言されている変数 s は他の関数では使用できません ( 別の関数で同じ名前の変数を宣言することはできますが 全く別の変数として扱われます このように ある関数の中で宣言されている変数のことをその関数の ソフトゼミ A 第 6 回関数 はじめに今まで printf や scanf など 予め用意されていた関数を使ってきました これら標準で用意されている関数を作ることは ( 特に入出力系は ) とても難しいのですが 関数は自作することができます というわけで 今回は自分で関数を定義して使っていく方法について学びましょう 関数とは C 言語での 関数 は 処理の途中で呼び出すことによって 定義されている

More information

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

Microsoft PowerPoint - program.ppt [互換モード] プログラミング演習 バージョン 1 担当教員 : 綴木馴 プログラムの決まりについて学ぶ おすすめする参考書 ザ C 戸川隼人サイエンス社 本日の予定 1. 授業の説明. 2. コンパイラーのインストール. プログラムの決まりについて学ぶ,P31 /* The most in C */ /* hello.c */ printf("hello,world n"); プログラムの決まり ( コメント )

More information

02: 変数と標準入出力

02: 変数と標準入出力 C プログラミング入門 基幹 7 ( 水 5) 09: ポインタ 文字列 Linux にログインし 以下の講義ページを開いておくこと http://www-it.sci.waseda.ac.jp/ teachers/w483692/cpr1/ 2016-06-08 1 関数できなかったこと 配列を引数として渡す, 戻り値として返す 文字列を扱う 呼び出し元の変数を直接書き換える 例 : 2 つの変数の値を入れ替える関数

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

5. F(, 0) = = 4 = 4 O = 4 =. ( = = 4 ) = 4 ( 4 ), 0 = 4 4 O 4 = 4. () = 8 () = 4

5. F(, 0) = = 4 = 4 O = 4 =. ( = = 4 ) = 4 ( 4 ), 0 = 4 4 O 4 = 4. () = 8 () = 4 ... A F F l F l F(p, 0) = p p > 0 l p 0 P(, ) H P(, ) P l PH F PF = PH PF = PH p O p ( p) + = { ( p)} = 4p l = 4p (p 0) F(p, 0) = p O 3 5 5. F(, 0) = = 4 = 4 O = 4 =. ( = = 4 ) = 4 ( 4 ), 0 = 4 4 O 4 =

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

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

c-all.dvi

c-all.dvi III(994) (994) from PSL (9947) & (9922) c (99,992,994,996) () () 2 3 4 (2) 2 Euler 22 23 Euler 24 (3) 3 32 33 34 35 Poisson (4) 4 (5) 5 52 ( ) 2 Turbo 2 d 2 y=dx 2 = y y = a sin x + b cos x x = y = Fortran

More information

4 4 θ X θ P θ 4. 0, 405 P 0 X 405 X P 4. () 60 () 45 () 40 (4) 765 (5) 40 B 60 0 P = 90, = ( ) = X

4 4 θ X θ P θ 4. 0, 405 P 0 X 405 X P 4. () 60 () 45 () 40 (4) 765 (5) 40 B 60 0 P = 90, = ( ) = X 4 4. 4.. 5 5 0 A P P P X X X X +45 45 0 45 60 70 X 60 X 0 P P 4 4 θ X θ P θ 4. 0, 405 P 0 X 405 X P 4. () 60 () 45 () 40 (4) 765 (5) 40 B 60 0 P 0 0 + 60 = 90, 0 + 60 = 750 0 + 60 ( ) = 0 90 750 0 90 0

More information

RX ファミリ用 C/C++ コンパイラ V.1.00 Release 02 ご使用上のお願い RX ファミリ用 C/C++ コンパイラの使用上の注意事項 4 件を連絡します #pragma option 使用時の 1 または 2 バイトの整数型の関数戻り値に関する注意事項 (RXC#012) 共用

RX ファミリ用 C/C++ コンパイラ V.1.00 Release 02 ご使用上のお願い RX ファミリ用 C/C++ コンパイラの使用上の注意事項 4 件を連絡します #pragma option 使用時の 1 または 2 バイトの整数型の関数戻り値に関する注意事項 (RXC#012) 共用 RX ファミリ用 C/C++ コンパイラ V.1.00 Release 02 ご使用上のお願い RX ファミリ用 C/C++ コンパイラの使用上の注意事項 4 件を連絡します #pragma option 使用時の 1 または 2 バイトの整数型の関数戻り値に関する注意事項 (RXC#012) 共用体型のローカル変数を文字列操作関数で操作する場合の注意事項 (RXC#013) 配列型構造体または共用体の配列型メンバから読み出した値を動的初期化に用いる場合の注意事項

More information

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 )

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 ) 1 f(x) a b f(x)dx = n A(x i ) (1) ix [a, b] n i A(x i ) x i 1 f(x) [a, b] n h = (b a)/n y h = (b-a)/n y = f (x) h h a a+h a+2h a+(n-1)h b x 1: 1 x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x

More information

num9.dvi

num9.dvi kanenko@mbk.nifty.com alexei.kanenko@docomo.ne.jp http://www.kanenko.com/ FORTRAN ( mandelbrot.f) FORTRAN COMPLEX C,Z,W, W=Z**2+C, w = z 2 +c. OK. W=X*Z+2-1/Z Z=CMPLX(X,Y)! x, y z = x+iy X=REAL(Z)! z x

More information