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

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

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

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

P05.ppt

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

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

PowerPoint Presentation

P03.ppt

Łñ“’‘‚2004


プリント

main

あっと! デジタル ver.7

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

double 2 std::cin, std::cout 1.2 C fopen() fclose() C++ std::fstream 1-3 #include <fstream> std::fstream fout; int a = 123; fout.open( "data.t

HTML

Microsoft Word - no15.docx

P02.ppt

超初心者用

P06.ppt

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

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

O(N) ( ) log 2 N

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

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

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

新版明解C言語 実践編

program.dvi

untitled

‚æ4›ñ

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

新版明解C言語入門編

joho07-1.ppt

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

comment.dvi

Microsoft Word - no11.docx

2004

double float

tuat1.dvi

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

2 3


r03.dvi

K227 Java 2

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

データ構造とアルゴリズム論

[ 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 4 2 EP) (EP) (EP)

I J

ohp03.dvi

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

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 )

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

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

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

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

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

BLOCK TYPE.indd

untitled

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

1.ppt

1 2

untitled

INDEX

INDEX


1002goody_bk_作業用

外為オンライン FX 取引 操作説明書

Microsoft Word - no15.docx

新・明解C言語 実践編

(ver. 1.3 (2018) ) yacc 1 1 yacc yacc (Yet Another Compiler Compiler) UNIX yacc yacc y *.y yacc ) yacc *.tab.h *.tab.c C C yacc yacc UNIX yacc bison 2

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

PowerPoint Presentation

r07.dvi

ohp07.dvi

C C UNIX C ( ) 4 1 HTML 1

01_OpenMP_osx.indd

Cプログラミング - 第8回 構造体と再帰

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

Microsoft PowerPoint - 11.pptx

Prog1_15th

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

output2010本文.indd

新コンフィギュレータのフレームワークについて

数理.indd

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

橡Pro PDF

ex01.dvi

講習No.12

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

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


導入基礎演習.ppt

ex01.dvi

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

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

2表紙

untitled

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

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

Transcription:

A/B (2010/10/08) Ver. 1.0 kurino@math.cst.nihon-u.ac.jp http://edu-gw2.math.cst.nihon-u.ac.jp/ kurino/2010/soft/soft.html 2010 10 8 A/B 1 2010 10 8 2 1 1 1.1 OHP.................................... 1 1.2....................................... 1 1.3.......................... 1 1.3.1 sample-001................................... 1 1.3.2 sample-002................................... 2 1.3.3 sample-003................................... 4 1.3.4 sample-004................................... 6 1.3.5 sample-005................................... 6 1.3.6 sample-006................................... 7 1.3.7 sample-007................................... 8 1.3.8 sample-008................................... 10 1.3.9 sample-009................................... 11 1.3.10 sample-010................................... 12 1.3.11 sample-011................................... 14 1.3.12 sample-012................................... 15 1.3.13 sample-013................................... 16 1.3.14 sample-014................................... 18 1.3.15 sample-015................................... 18 1.3.16 sample-016................................... 20 1.3.17 sample-017................................... 21 1.3.18 sample-018................................... 23 1 http://edu-gw2.math.cst.nihon-u.ac.jp/ kurino/2010/soft/soft.html 2 http://edu-gw2.math.cst.nihon-u.ac.jp/ kurino/2010/soft/20101008/20101008.html 1

1 1.1 OHP OHP (HTML) 3 (PDF) 4 1.2 8.1 ( Text p.184-189 ) > 1.3 1.3.1 sample-001 Download : sample-001.c 5 ( SJIS 6 ) 1: sample-001.c * 5 * * main int main ( void ) { int numbers[5]; int index; // 5 // printf ( "5 \n" ); for ( index = 0; index < 5; index++ ) { printf ( "%2d : ", index + 1 ); scanf ( "%d", &numbers[index] ); // index printf ( "--- ---\n" ); for ( index = 0; index < 5; index++ ) { printf ( "%5d\n", numbers[ 4 - index ] );? : 3 ohp/html/index.html 4 ohp/ohp.pdf 5 program/sample-001.c 6 program/sjis/sample-001.c // 4 1

47304 3 2957 602 73 1: sample-001 5 1 : 47304 2 : 3 3 : 2957 4 : 602 5 : 73 --- --- 73 602 2957 3 47304 2: sample-001.c 1.3.2 sample-002 Download : sample-002.c 7 ( SJIS 8 ) 2: sample-002.c 7 program/sample-002.c 8 program/sjis/sample-002.c 2

* NUMBER_OF_NUMBERS * * * NUMBER_OF_NUMBERS * 5 sample-001.c * 5 #define NUMBER_OF_NUMBERS 5 * main int main ( void ) { int numbers[number_of_numbers]; int index; //NUMBER_OF_NUMBERS // printf ( "%d \n", NUMBER_OF_NUMBERS ); for ( index = 0; index < NUMBER_OF_NUMBERS; index++ ) { printf ( "%2d : ", index + 1 ); scanf ( "%d", &numbers[index] ); // index printf ( "--- ---\n" ); for ( index = 0; index < NUMBER_OF_NUMBERS; index++ ) { printf ( "%5d\n", numbers[ (NUMBER_OF_NUMBERS-1) - index ] ); 47304 3 2957 602 73 3: 3

sample-002 5 1 : 47304 2 : 3 3 : 2957 4 : 602 5 : 73 --- --- 73 602 2957 3 47304 4: sample-002.c 1.3.3 sample-003 Download : sample-003.c 9 ( SJIS 10 ) 3: sample-003.c * NUMBER_OF_NUMBERS * * * END_OF_NUMBERS = NUMBER_OF_NUMBERS - 1 #define NUMBER_OF_NUMBERS 5 #define END_OF_NUMBERS (NUMBER_OF_NUMBERS-1) * main int main ( void ) { int numbers[number_of_numbers]; int index; //NUMBER_OF_NUMBERS // printf ( "%d \n", NUMBER_OF_NUMBERS ); for ( index = 0; index < NUMBER_OF_NUMBERS; index++ ) { 9 program/sample-003.c 10 program/sjis/sample-003.c 4

printf ( "%2d : ", index + 1 ); scanf ( "%d", &numbers[index] ); // index printf ( "--- ---\n" ); for ( index = 0; index < NUMBER_OF_NUMBERS; index++ ) { printf ( "%5d\n", numbers[ END_OF_NUMBERS - index ] ); // END_OF_NUMBERS 47304 3 2957 602 73 5: sample-003 5 1 : 47304 2 : 3 3 : 2957 4 : 602 5 : 73 --- --- 73 602 2957 3 47304 6: sample-003.c 5

1.3.4 sample-004 Download : sample-004.c 11 ( SJIS 12 ) 4: sample-004.c * * SOME_VALUE 2 + 3.. 5..? #define SOME_VALUE 2 + 3 printf ( "%d\n", SOME_VALUE * 4 ); // 5 4 = 20? sample-004 14 7: sample-004.c 1.3.5 sample-005 Download : sample-005.c 13 ( SJIS 14 ) 5: sample-005.c * * 11 program/sample-004.c 12 program/sjis/sample-004.c 13 program/sample-005.c 14 program/sjis/sample-005.c 6

#define SOME_VALUE (2 + 3) printf ( "%d\n", SOME_VALUE * 4 ); // 20 4.0 3 8: sample-005 20 9: sample-005.c 1.3.6 sample-006 Download : sample-006.c 15 ( SJIS 16 ) 6: sample-006.c * if then else * IF / THEN / ELSE / ENDIF #define IF if ( #define THEN ) { 15 program/sample-006.c 16 program/sjis/sample-006.c 7

#define ELSE else { #define ENDIF int num; int abs; printf ( " \n" ); printf ( " : " ); scanf ( "%d", &num ); IF num < 0 THEN abs = - num; printf ( "%d \n", num ); ELSE abs = num; printf ( "%d \n", num ); ENDIF printf ( "%d %d \n", num, abs ); -3 10: sample-006 : -3-3 -3 3 11: sample-006.c 1.3.7 sample-007 Download : sample-007.c 17 ( SJIS 18 ) 17 program/sample-007.c 18 program/sjis/sample-007.c 8

7: sample-007.c * ever * #define ever (;;) int num; printf ( "-1 \n" ); for ever { //.. printf ( " : " ); scanf ( "%d", &num ); if ( num == -1 ) { break; printf ( " %d \n", num ); printf ( "%d \n", num ); 4 9 1-5 0 6-1 12: 9

sample-007-1 : 4 4 : 9 9 : 1 1 : -5-5 : 0 0 : 6 6 : -1-1 13: sample-007.c 1.3.8 sample-008 Download : sample-008.c 19 ( SJIS 20 ) 8: sample-008.c * fromto * fromto int fromto ( int from, int to ) { return to - from + 1; int num1; int num2; 19 program/sample-008.c 20 program/sjis/sample-008.c 10

printf ( " \n" ); printf ( " : " ); scanf ( "%d", &num1 ); printf ( " : " ); scanf ( "%d", &num2 ); printf ( "%d %d %d \n", num1, num2, fromto( num1, num2 ) ); 15 34 14: sample-008 : 15 : 34 15 34 20 15: sample-008.c 1.3.9 sample-009 Download : sample-009.c 21 ( SJIS 22 ) 9: sample-009.c * fromto * fromto 21 program/sample-009.c 22 program/sjis/sample-009.c 11

#define fromto(from,to) ((TO) - (FROM) + 1) int num1; int num2; printf ( " \n" ); printf ( " : " ); scanf ( "%d", &num1 ); printf ( " : " ); scanf ( "%d", &num2 ); printf ( "%d %d %d \n", num1, num2, fromto( num1, num2 ) ); 15 34 16: sample-009 : 15 : 34 15 34 20 17: sample-009.c 1.3.10 sample-010 Download : sample-010.c 23 ( SJIS 24 ) 10: sample-010.c 23 program/sample-010.c 24 program/sjis/sample-010.c 12

* ( ) * sqr_int / int sqr_int( int x ) { return x * x; * sqr_double / double sqr_double ( double x ) { return x * x; int num_int; double num_double; printf ( " \n" ); printf ( " : " ); scanf ( "%d", &num_int ); printf ( " %d %d \n", num_int, sqr_int ( num_int ) ); printf ( " \n" ); printf ( " : " ); scanf ( "%lf", &num_double ); printf ( " %lf %lf \n", num_double, sqr_double ( num_double ) ); 13

4 7.6 18: sample-010 : 4 4 16 : 7.600000 7.600000 57.760000 19: sample-010.c 1.3.11 sample-011 Download : sample-011.c 25 ( SJIS 26 ) 11: sample-011.c * ( ) * ( ) #define sqr(x) ((X)*(X)) int num_int; double num_double; printf ( " \n" ); printf ( " : " ); scanf ( "%d", &num_int ); printf ( " %d %d \n", num_int, sqr ( num_int ) ); 25 program/sample-011.c 26 program/sjis/sample-011.c 14

printf ( " \n" ); printf ( " : " ); scanf ( "%lf", &num_double ); printf ( " %lf %lf \n", num_double, sqr ( num_double ) ); 4 7.6 20: sample-011 : 4 4 16 : 7.600000 7.600000 57.760000 21: sample-011.c 1.3.12 sample-012 Download : sample-012.c 27 ( SJIS 28 ) 12: sample-012.c * ( ) 27 program/sample-012.c 28 program/sjis/sample-012.c 15

* ( ) #define sqr(x) ((X)*(X)) int num_int; printf ( " \n" ); printf ( " : " ); scanf ( "%d", &num_int ); printf ( " %d + 1 ", num_int ); printf ( " %d \n", sqr ( ++num_int ) ); 5 22: sample-012 : 5 5 + 1 42 23: sample-012.c 1.3.13 sample-013 Download : sample-013.c 29 ( SJIS 30 ) 13: sample-013.c 29 program/sample-013.c 30 program/sjis/sample-013.c 16

* ( ) * sqr_int / int sqr_int( int x ) { return x * x; int num_int; printf ( " \n" ); printf ( " : " ); scanf ( "%d", &num_int ); printf ( " %d + 1 ", num_int ); printf ( " %d \n", sqr_int ( ++num_int ) ); 5 24: sample-013 : 5 5 + 1 36 25: sample-013.c 17

1.3.14 sample-014 Download : sample-014.c 31 ( SJIS 32 ) 14: sample-014.c * * input #define input(msg,type,var) #define output(msg,var); (printf (MSG), scanf(type,&var)) (printf (MSG,VAR)) int num_int; double num_double; input( " \n", "%d", num_int ); output( " %d \n", num_int ); input( " \n", "%lf", num_double ); output( " %f \n", num_double ); 4 7.6 26: 1.3.15 sample-015 Download : sample-015.c 33 ( SJIS 34 ) 15: sample-015.c 31 program/sample-014.c 32 program/sjis/sample-014.c 33 program/sample-015.c 34 program/sjis/sample-015.c 18

sample-014 4 4 7.600000 7.600000 27: sample-014.c * * make_swap #define make_sqr(name,type) \ Type Name( Type n ) {\ return n * n;\ * make_sqr(sqr_int,int) make_sqr(sqr_double,double) int num_int; double num_double; printf ( " \n" ); printf ( " : " ); scanf ( "%d", &num_int ); printf ( " %d %d \n", num_int, sqr_int ( num_int ) ); printf ( " \n" ); 19

printf ( " : " ); scanf ( "%lf", &num_double ); printf ( " %lf %lf \n", num_double, sqr_double ( num_double ) ); 4 7.6 28: sample-015 : 4 4 16 : 7.600000 7.600000 57.760000 29: sample-015.c 1.3.16 sample-016 Download : sample-016.c 35 ( SJIS 36 ) 16: sample-016.c * * int factrial ( int n ) { 35 program/sample-016.c 36 program/sjis/sample-016.c 20

if ( n < 2 ) { return 1; else { return n * factrial ( n - 1 ); int num_int; printf ( " \n" ); printf ( " : " ); scanf ( "%d", &num_int ); printf ( " %d %d \n", num_int, factrial ( num_int ) ); 5 30: sample-016 : 5 5 120 31: sample-016.c 1.3.17 sample-017 Download : sample-017.c 37 ( SJIS 38 ) 17: sample-017.c 37 program/sample-017.c 38 program/sjis/sample-017.c 21

* * int sum_two ( int n, int m ) { return n + m; * int sum_three ( int l, int m, int n ) { return sum_two ( sum_two ( l, m ), n ); * int sum_four ( int a, int b, int c, int d ) { return sum_two ( sum_three ( a, b, c ), d ); int a; int b; int c; int d; printf ( " 4 \n" ); scanf ( "%d", &a ); scanf ( "%d", &b ); scanf ( "%d", &c ); scanf ( "%d", &d ); printf ( " 4 %d \n", sum_four ( a, b, c, d ) ); 22

5 2 8 9 32: sample-017 4 5 2 8 9 4 24 33: sample-017.c 1.3.18 sample-018 Download : sample-018.c 39 ( SJIS 40 ) 18: sample-018.c * * N int sum_array ( int ary[], int size ) { if ( size > 0 ) { return sum_array ( ary, size - 1 ) + ary[ size - 1 ]; else { 39 program/sample-018.c 40 program/sjis/sample-018.c 23

#define NUM 4 int a[num]; int i; printf ( " %d \n", NUM ); for ( i = 0; i < NUM; i++ ) { scanf ( "%d", &a[i] ); printf ( "%d %d \n", NUM, sum_array ( a, NUM ) ); 5 2 8 9 34: sample-018 4 5 2 8 9 4 24 35: sample-018.c 24