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

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

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

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( )

超初心者用

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n

卒 業 研 究 報 告.PDF

Microsoft PowerPoint - kougi9.ppt

ex14.dvi

ファイル入出力

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

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

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

1.ppt

slide4.pptx

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

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

Microsoft PowerPoint - 10Com2.ppt

ファイル入出力

gengo1-12

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

gengo1-12

新・明解C言語 実践編

新版明解C言語 実践編

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

C言語入門

Microsoft PowerPoint - kougi4.ppt

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

r07.dvi

ohp07.dvi

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

ohp03.dvi

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

情報処理演習 B8クラス

joho07-1.ppt

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

ohp08.dvi

gengo1-12

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

Microsoft PowerPoint - kougi8.ppt

r08.dvi

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

tuat2.dvi

‚æ4›ñ

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

tuat1.dvi

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

(K&R 2.9) ~, &,, >>, << 2. (K&R 5.7) 3. (K&R 5.9) 4. (K&R 5.10) (argc argv atoi(), atof() ) 5. (K&R 7.5) (K&R 7.6) - FILE, stdin, stdout, std

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

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

Minimum C Minimum C Minimum C BNF T okenseq W hite Any D

計算機プログラミング

C

PowerPoint プレゼンテーション

Microsoft PowerPoint - kougi2.ppt

Microsoft PowerPoint - guidance.ppt

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

PowerPoint Presentation

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

Microsoft PowerPoint - kougi6.ppt

P05.ppt

file"a" file"b" fp = fopen("a", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose(fp); fp = fopen("b", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose

PowerPoint プレゼンテーション

pptx

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

Microsoft Word - 06

program.dvi

double float

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

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

comment.dvi

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

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

memo

ゲームエンジンの構成要素

コンピュータ概論

I J

untitled

PowerPoint プレゼンテーション

ポインタ変数

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

untitled

lexex.dvi

Microsoft PowerPoint pptx

Microsoft PowerPoint pptx

untitled

WinHPC ppt

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

橡Pro PDF

10

ポインタ変数

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

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

memo

C言語講座 ~ファイル入出力編~

ディジタル信号処理

Transcription:

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 1.2.......................... 1 1.3.............................. 17 1.4....................................... 18 1.4.1 20181019-01 : printf........................... 18 1.4.2 20181019-02 : scanf............................ 19 1.4.3 20181019-03 :.................... 20 1.4.4 20181019-04 : while........................... 21 1 http://edu-gw2.math.cst.nihon-u.ac.jp/ kurino/2018/soft/soft.html 2 http://edu-gw2.math.cst.nihon-u.ac.jp/ kurino/2018/soft/20181019/20181019.html 1

1 1.1 OHP OHP (HTML) 3 (PDF) 4 1.2 Download : sample-001.c 5 1: sample-001.c 2018/10/19 sample-001.c Hello, World.. cc -Ic:\usr\c\include -o sample-001.exe sample-001.c sample-001 main int main( double argc, char argv[] ) printf ( "Hello, World\n" ); Download : sample-002.c 6 2: sample-002.c 3 ohp/html/index.html 4 ohp/ohp.pdf 5 program/sample-001.c 6 program/sample-002.c 1

./sample-001.exe Hello, World 1: sample-001.c 2018/10/19 sample-002.c n^2 cc -Ic:\usr\c\include -o sample-002.exe sample-002.c sample-002 #include "s_input.h" #include "s_print.h" http://ja.wikipedia.org/wiki/%e5%b9%b3%e6%96%b9%e6%95%b0 main int main ( int argc, char argv[] ) int n = 13; n=13 n^2 = nn = 1313 = 169 int i = 0; i 0 n-1 int sum = 0; sum odd 0 int odd = 1; odd 1 2 ( ) while ( i < n ) i n sum = sum + odd; sum odd = odd + 2; 2 i = i + 1; s_print_int ( sum ); n^2.. s_print_newline(); 2

./sample-002.exe 169 2: sample-002.c Download : sample-003.c 7 3: sample-003.c 2018/10/19 sample-003.c printf cc -Ic:\usr\c\include -o sample-003.exe sample-003.c sample-003 main int main( int argc, char argv[] ) printf ( "5 + 4 = %d\n", 5 + 4 ); %d 9 ( = 5 + 4 )./sample-003.exe 5 + 4 = 9 3: sample-003.c Download : sample-004.c 8 4: sample-004.c 7 program/sample-003.c 8 program/sample-004.c 3

2018/10/19 sample-004.c printf ( ) cc -Ic:\usr\c\include -o sample-004.exe sample-004.c sample-004 main int main( int argc, char argv[] ) printf ( "%d + %d = %d\n", 5, 4, 5 + 4 ); %d./sample-004.exe 5 + 4 = 9 4: sample-004.c Download : sample-005.c 9 5: sample-005.c 2018/10/19 sample-005.c printf ( ) cc -Ic:\usr\c\include -o sample-005.exe sample-005.c 9 program/sample-005.c 4

sample-005 main int main( int argc, char argv[] ) printf ( " %%d %d \n", 123 ); printf ( " %%f %f \n", 123.456 ); printf ( " %%c %c \n", Z ); printf ( " %%s %s \n", "pqr" );./sample-005.exe %d 123 %f 123.456000 %c Z %s pqr 5: sample-005.c Download : sample-006.c 10 6: sample-006.c 2018/10/19 sample-006.c printf ( ) 10 program/sample-006.c 5

cc -Ic:\usr\c\include -o sample-006.exe sample-006.c sample-006 main int main( int argc, char argv[] ) printf ( " \n" ); printf ( "%d, %f, %c, %s\n", 10, 2.3, x, "abc" );./sample-006.exe 10, 2.300000, x, abc 6: sample-006.c Download : sample-007.c 11 7: sample-007.c 2018/10/19 sample-007.c scanf cc -Ic:\usr\c\include -o sample-007.exe sample-007.c sample-007 main 11 program/sample-007.c 6

int main( int argc, char argv[] ) int i; printf ( " : " ); scanf ( "%d", &i ); %d i & ( ) printf ( " %d \n", i ); 123 7:./sample-007.exe < sample-007.in : 123 123 8: sample-007.c Download : sample-008.c 12 8: sample-008.c 2018/10/19 sample-008.c scanf ( ) cc -Ic:\usr\c\include -o sample-008.exe sample-008.c sample-008 12 program/sample-008.c 7

main int main( int argc, char argv[] ) int i; double x; printf ( " : " ); scanf ( "%d", &i ); %d i & ( ) printf ( " %d \n", i ); printf ( " : " ); scanf ( "%lf", &x ); %lf x & ( ) printf ( " %f \n", x ); 123 456.789 9:./sample-008.exe < sample-008.in : 123 123 : 456.789000 456.789000 10: sample-008.c Download : sample-009.c 13 13 program/sample-009.c 8

9: sample-009.c 2018/10/19 sample-009.c Enter # A A [ENTER] # [ENTER] cc -Ic:\usr\c\include -o sample-009.exe sample-009.c sample-009 main int main( int argc, char argv[] ) int ch; (int ) ch = getchar(); putchar ( ch ); A 11:./sample-009.exe < sample-009.in A A 12: sample-009.c Download : sample-010.c 14 10: sample-010.c 14 program/sample-010.c 9

2018/10/19 sample-010.c cc -Ic:\usr\c\include -o sample-010.exe sample-010.c sample-010 main int main( int argc, char argv[] ) int ch; (int ) ch = getchar(); putchar ( ch ); ch = getchar(); ( [Enter]) putchar ( ch ); A 13:./sample-010.exe < sample-010.in A A 14: sample-010.c Download : sample-011.c 15 11: sample-011.c 15 program/sample-011.c 10

2018/10/19 sample-011.c cc -Ic:\usr\c\include -o sample-011.exe sample-011.c sample-011 main int main( int argc, char argv[] ) int ch; ch = getchar(); while ( ch!= EOF ) EOF.. EOF End Of File( ) EOF ( ) ch (int ) EOF.. ch char EOF putchar ( ch ); ch = getchar(); (EOF..) Windows EOF Ctrol-Z ( ^Z : [Ctrl] Z ) ( OS.. ) This is first line. And, it is second line. Last, it is third line. 15: 11

./sample-011.exe < sample-011.in This is first line. This is first line. And, it is second line. And, it is second line. Last, it is third line. Last, it is third line. 16: sample-011.c Download : sample-012.c 16 12: sample-012.c 2018/10/19 sample-012.c fgtec, fputc cc -Ic:\usr\c\include -o sample-012.exe sample-012.c sample-012 main int main( int argc, char argv[] ) int ch; ch = fgetc ( stdin ); stdin ( ) while ( ch!= EOF ) EOF fputc ( ch, stdout ); stdout ( ) ch = fgetc ( stdin ); 16 program/sample-012.c 12

This is first line. And, it is second line. Last, it is third line. 17:./sample-012.exe < sample-012.in This is first line. And, it is second line. Last, it is third line. 18: sample-012.c Download : sample-013.c 17 13: sample-013.c 2018/10/19 sample-013.c stdout stderr cc -Ic:\usr\c\include -o sample-013.exe sample-013.c sample-013 main int main( int argc, char argv[] ) printf ( "O: \n" ); printf fprintf ( stderr, "E: \n" ); fprintf stderr fprintf ( stdout, "O: \n" ); fprintf stdout fprintf ( stderr, "E: \n" ); 17 program/sample-013.c 13

O: E: O: E: 19: sample-013.c Download : sample-014.c 18 14: sample-014.c 2018/10/19 sample-014.c fopen cc -Ic:\usr\c\include -o sample-014.exe sample-014.c sample-014 main int main( int argc, char argv[] ) FILE ifp; ifp = fopen ( "sample-014.c", "r" ); sample-014.c if ( ifp == NULL ) Open.. fprintf ( stderr, " \n" ); 18 program/sample-014.c 14

( ) else Open int ch; ch = fgetc ( ifp ); fgetc while ( ch!= EOF ) EOF putchar ( ch );.. ch = fgetc ( ifp ); fclose ( ifp ); Download : sample-015.c 19 15: sample-015.c 2018/10/19 sample-015.c fopen cc -Ic:\usr\c\include -o sample-015.exe sample-015.c sample-015 main int main( int argc, char argv[] ) FILE ofp; ofp = fopen ( "sample-015.txt", "w" ); sample-015.txt sample-015.txt if ( ofp == NULL ) Open.. fprintf ( stderr, " \n" ); 19 program/sample-015.c 15

./sample-014.exe 2018/10/19 sample-014.c fopen cc -Ic:\usr\c\include -o sample-014.exe sample-014.c sample-014 main int main( int argc, char argv[] ) FILE ifp; ifp = fopen ( "sample-014.c", "r" ); sample-014.c if ( ifp == NULL ) Open.. fprintf ( stderr, " \n" ); ( ) else Open int ch; ch = fgetc ( ifp ); fgetc while ( ch!= EOF ) EOF putchar ( ch );.. ch = fgetc ( ifp 16 ); fclose ( ifp );

( ) else Open int ch; ch = getchar (); while ( ch!= EOF ) fputc ( ch, ofp );.. ch = getchar (); fclose ( ofp ); sample-015.txt Fist Line Sencod Line Last Line 21:./sample-015.exe < sample-015.in Fist Line Sencod Line Last Line 22: sample-015.c 1.3 20 20 p/ 17

1.4 : 1.4.1 20181019-01 : printf Download : 20181019-01.c 21 16: 20181019-01.c CNAME-01 20181019 20181019-01-QQQQ.c printf main int main( int argc, char argv[] ) int ia = 7; int ib = 15; double da = 3.14; double db = 1.59; printf ( " o: + o: = o: \n", p:, q:, p: + q: ); printf ( " r: / r: = r: \n", s:, u:, s: / u: ); abc123 23: 21 ex/01/q/01.c 18

./20181019-01-QQQQ.exe 7 + 15 = 22 3.140000 / 1.590000 = 1.974843 24: 20181019-01.c 1.4.2 20181019-02 : scanf Download : 20181019-02.c 22 17: 20181019-02.c CNAME-02 20181019 20181019-02-QQQQ.c scanf main int main( int argc, char argv[] ) int i; double d; printf ( " : " ); scanf ( " p: ", q: ); printf ( " %d \n", i ); printf ( " : " ); scanf ( " r: ", s: ); printf ( " %f \n", d ); 22 ex/02/q/02.c 19

123 456.789 25:./20181019-02-QQQQ.exe : 123 123 : 456.789000 456.789000 26: 20181019-02.c 1.4.3 20181019-03 : Download : 20181019-03.c 23 18: 20181019-03.c CNAME-03 CDATE FILENAME ( a, b, c ) a, b 123, 4 c a b c #include "s_print.h" main int main( int argc, char argv[] ) a int a; b c int c; 23 ex/03/q/03.c 20

a 123 a = 123; b 4 c a b c s_print_string ( " c " ); s_print_int ( c ); s_print_string ( " \n" ); 12.34 27:./20181019-03-QQQQ.exe c 127 28: 20181019-03.c 1.4.4 20181019-04 : while Download : 20181019-04.c 24 19: 20181019-04.c CNAME-04 CDATE FILENAME 24 ex/04/q/04.c 21

while #include "s_print.h" main int main( int argc, char argv[] ) odd ( 1 ) int odd = 1; sum ( 0 ) int sum = 0; sum = 1 + 3 +.. + 9 = 25 = 5^2 odd 9 while ( q: ) sum odd odd odd = odd + 2; sum s_print_string ( "1 9 " ); s_print_int ( sum ); s_print_string ( " \n" ); 12.34 29: 22

./20181019-04-QQQQ.exe 1 9 25 30: 20181019-04.c 23