Xemacs Emacs

Size: px
Start display at page:

Download "Xemacs Emacs"

Transcription

1

2 Xemacs Emacs void printf() main (relational operartor) (logical operartor) if...else switch...case loop while while do...while for break continue goto return char copy duplicate compare concatenate typedef struct tm #include #define

3 FILE fopen() : fclose() fflush() fread() fwrite() system() C complex.h tgmath.h (sorting) C.5.3 diff C.5.4 date C.5.5 sort C C.6.1 tar C.6.2 gzip, gunzip C.6.3 bzip2, bunzip C.6.4 compress, uncompress C.6.5 lha,zip C.6.6 mtools C.6.7 split C.6.8 uuencode, uudecode C.7 bc A 57 A A B 58 B B.2 PAD B.2.1 pad2ps C Linux UNIX 60 C.1 Login/Logout C.1.1 login C.1.2 logout C C C C C C.3 UNIX C C C C C.4 > >> C C.5.1 indent C.5.2 grep

4 C C UNIX OS (Operating sysytem) C C C C C 1999 C C () C & Q&A C Study C C 13 lesson C C/C++ C The C Programming Language, Second Edition C B. W. Kernighan Dennis M. Ritchie C K&R Dennis M. Ritchie C C 12 n n C 1fefefefefefefefefefefe1 1fefefefefefefefefefefe1 1

5 C webmail Webmail webmail Ctrl + \ + xwnmo Xemacs Xemacs xwnmo webmail 1 Webmail webmail Mozilla Netscape WWW webmail URL Login Name Password login 1 C char 1 =8 256 ASCII 7 man ascii 2 3 (JIS) 8 7 JIS 7 JIS 7 JIS 8 Linux UNIX OS Enhanced Unix CodeMS-DOS/Win MAC JIS MS 1 webmail 2

6 C OS UNIX OS nkf, lv nkf Win32 man nkf EUC-J nkf -e filename > filename.euc mv filename.euc filename nkf nkf -e filename > filename JIS -e -s JIS -j 2 qkc qkc -e filename filename EUC-J UNICODE ascii ascii 1 (UTF8) MS-Win S-JIS EUC-J JIS UNICODE JIS UTF8 UNICODE 1 lv UNICODE UTF8 JIS, EUC-J, S-JIS, UTF8 man lv 1 OS OS Linux EUC (EUC-J) LF MS-Win JIS (S-JIS) CR+LF MAC JIS CR OS 1 3 OS (LF) (CR) OS unix2dos dos2unix MS- DOS/Win UNIX CR+LF UNIX LF dos2unix file UNIX DOS unix2dos file perl MS-DOS/Win CR+LF Linux LF CR perl -p -e "s/\r//" <dosfile >unixfile LF CR LF perl -p -e "s/\n/\r\n/" <unixfile >dosfile 3

7 C nkf UNIX file /etc/magic $ file ex0 ex0: ELF 32-bit LSB executable, Intel 80386, version 1, dynamically linked, not stripped $ file ex0.c ex0.c: C program text $ file text00.tex text00.tex: International language text Enter 1.9 nkf UNIX nkf --unix dosfile > unixfile MS-DOS/Win UNIX nkf -OW --unix file 1fefefefefefefefefefefe1 Webmail Linux MS-DOS/Win nkf unix2dos dos2unix 1fefefefefefefefefefefe1 4

8 C C GNU gcc foo.c bar $ gccfoo.c -o bar -lm -o a.out -lm -Wall -Wstrict-prototypes C C.c.C.cc.cpp c++ Command BASIC 2 source source source compile File object object link execute command Process execute running interpret running 2 Hello Wold! ( i ) 1 Xemacs Emacs ex02.c ( ii ) gcc hello (iii)./hello 1 ex02.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : printf("hello World!\n"); 8 : return (0); 9 : } C 3 main () { } main 5,6,8,9 7 printf("...") " \ \n \t column \020 8 \x0d 16 printf % 7,8 ; 5

9 C Xemacs X gnome-term kterm rxvt etc. *term gcc ( i ) *term $ xemacs & & Xemacs (iii) 1 ( ) (iv) 3 Save ( v ) Xemacs *term eris061: $ C $ $ gcc ex02.c -o hello -lm UNIX OS (vi) ls(list) $ ls hello hello* hello 3 Xemacs ( ii ) Open Find file: ( ex02.c) (vii) hello./ $./hello *term UNIX secure PATH PATH./ PATH 4 Xemacs 1.2 Xemacs X Window System X X 6

10 C 1 xwnmo kinput2 Xemacs X Mozilla Web Mail X (Free)Wnn CannaSj3 SKK Wnn7 Atok MS-Windows xwnmo Wnn Emacs GNU Emacs Emacs X X X xwnmo Emacs Wnn egg xwnmo egg+wnn xwnmo 2 2 xwnmo Ctrl + \ Ctrl + w Space Ctrl + l Enter Ctrl + o Ctrl + i egg+wnn UNIX Wnn FAQ FAQ Linux (PDF) Linux Magazine 3 ( i ) ( ii ) (iii) Emacs Emacs Emacs tutorial Emacs 3 3 Emacs Ctrl + g 1 Ctrl + f 1 Ctrl + b Ctrl + p Ctrl + n Ctrl + a Ctrl + e Alt + < Alt + > 1 Ctrl + v 1 Alt + v Ctrl + l Ctrl + d Ctrl + h Ctrl + k Alt + k Ctrl + y Home Page Down Page Up Back Space 7

11 C 1 4 Emacs tutorial Emacs Ctrl/ESC 5 UNIX 1 \t \v \r 2 q01.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : printf("\ttab\ttab\ttab\ttab\n"); 8 : printf("\tht\vvt\tht\vvt\n"); 9 : printf("cr\rcr\rcr\rcr\r\n"); 10 : 11 : return (0); 12 : } ex06.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : printf("7 + 3 = %d\n", 7 + 3); 8 : printf("7-3 = %d\n", 7-3); 9 : printf("7 * 3 = %d\n", 7 * 3); 10 : printf("7 / 3 = %d\n", 7 / 3); 11 : printf("7 mod 3 = %d\n", 7 % 3); 12 : printf("7 + 3 = %f\n", ); 13 : printf("7-3 = %f\n", ); 14 : printf("7 * 3 = %e\n", 7. * 3); 15 : printf("7 / 3 = %e\n", 7. / 3); 16 : 17 : return (0); 18 : } %d %f %e int1 % int2 int1 int2 7/ q03.c q03.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : printf("7-3 * 4 = %d\n", 7-3 * 4); 8 : printf("(7-3) * 4 = %d\n", (7-3) * 4); 9 : printf("7 + 3 %% 4 = %d\n", % 4); 10 : printf("(7 + 3) %% 4 = %d\n", (7 + 3) % 4); 11 : 12 : return (0); 13 : } 6 ex06.c 8

12 C 1 1fefefefefefefefefefefe1 X KDE GNOME Emacs21 C gcc gcc foo.c -o bar -lm C main #include <stdio.h> #include <stdlib.h> #include <math.h> int main(int argc, char **argv) {... } ; printf ( printf(""); printf(" + ", ); 5 Knoppix-3.1 KDE Emacs21 1fefefefefefefefefefefe1 1CD Linux MS-Windows MS-Windows C Linux C Linux MS-Windows Linux MS-Windows 1CD Linux CD-ROM X 1 KNOPPIX 5 CD-ROM 6 Knoppix-3.1 Xemacs GUI GNU Emacs Ver.21 egg+wnn KNOPPIX Knopper KNOPPIX/Math 9

13 C 2 2 C [] void void UNIX X Window System X XCreateSimpleWindow() my My 7 1 d do cpu_athlon 386_cpu flag-png US$ _arg1 INTEGER Int (tag) () 2.1 A Z a z C auto break case char const continue default do double else enum extern float for goto if int long register return short singed sizeof static struct switch typedef union unsigned void volatile while inline C99 restrict C99 Bool C99 Complex C99 Imaginary C99 C ANSI(American National Standards Institute) X3.159 ISO 1990 ISO C99 C char short int int long int long long int 5 unsinged singed (/usr/include/)limit.h 4 32bit CPU 4 (32bit CPU) size Bool C99 1 0,1 char unsigned char signed char short unsigned short int unsigned int long unsigned long long long C unsigned 8 0 long lomg C math.h sin cos 1 do, 386 cpu, flag-png, US$ 10

14 C 2 char 255 char char ascii man ascii float double long double IEEE GCC (/usr/include/)ieee754.h 5 32bit CPU 5 (32bit CPU) size float 4 1.2E E+38 6 double 8 2.3E E long double E E float float CPU double float double C99 C C++ FORTRAN C ANSI C99 complex.h double _Complex x; long double _Complex y=3+4i; void void void func(...) double func(void) void 8 [ ] 5 ex08.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : double r; 8 : 9 : printf("radius = "); 10 : scanf("%lf", &r); 11 : printf("area = %f\n", M_PI * r * r); 12 : & 13 : return (0); 14 : } ex08 $ gcc ex08.c -o ex08 -lm ex08 $./ex08 radius = 3 area = scanf("%lf",&r) &r r C 8 %lf 9 %f f float printf %f double scanf %f double %lf ( ) 10 M_PI π (/usr/include/)math.h 11

15 C printf() 6 d, i int 10 o unsigned int 8 u unsigned int 10 x, X unsigned int 16 e, E double 10 f double 10 g, G double f e 1 a, A C99 double 16 2 c char, int int unsigned char s 3 NUL \0 p 16 n int * % % 1 man 3 printf 2 C99 3 char printf () ex08.c 11 printf("area = %f\n", M_PI*r*r); printf() man 3 printf (conversion specification) %[][][. ] %12.8f %20.15g %-8.6e %d %03d %80s %% %n %p %. 6 float # o X,x 16 0x 0X a,a,e,e,f,g,g ex09u.c 6 ex09.c 4 : 5 : int main(void) 6 : { 7 : int i; 8 : double x; 9 : 10 : printf("integer i = "); 11 : scanf("%d", &i); 12 : printf("double x = "); 13 : scanf("%lf", &x); 14 : printf("\n"); 15 : 16 : printf("%%d\t i = %d\n", i); 17 : printf("%%8d\t i = %8d\n", i); 18 : printf("%%010d\t i = %010d\n", i); 19 : 20 : printf("%%f\t x = %f\n", x); 21 : printf("%%4.3f\t x = %4.3f\n", x); 22 : printf("%%e\t x = %e\n", x); 23 : printf("%%12.8g\t x = %12.8g\n", x); 24 : 25 : return (0); 26 : } 12

16 C q04.c 5 q05.c 2.4 main scanf main **argv argv main foo arg1 arg2 arg3... foo argv[0] foo argv[1] arg1 argv[2] arg2... main int argc, char **argv aragc argc main 7 ex10.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : double r; 8 : 9 : r = atof(argv[1]); 10 : printf("area = %f\n", M_PI * r * r); 11 : 12 : return (0); 13 : } [ ] ex10.c 9 atof() ascii to float double int atoi() long int atol() $./ex10 3 area = $./ex10 Segmentation fault (core dumped) atof 6 UNIX 7 x y : pow(x,y) 8 M PI math.h a, b, c A Heron A = ( s(s a)(s b)(s c) s = a + b + c ) 2 scanf main **argv 1fefefefefefefefefefefe1 [] unsigned signed float double 1fefefefefefefefefefefe1 13

17 C C 0 (false) Bool 1 0 (true) (relational operartor) () (comprison) 1 0 int => =< 3.3 (logical operartor) 9C () : 1 0 && (x y) (x y)! ( x) x && y x y x y 1 0 x y 1 0!x x (p q) T F 10 p p q p q p q p q F T T T T T F T F F T F T F T F T T T F F F F T 8 : 1 0 < x < y x y 1 0 <= x <= y x y 1 0 > x > y x y 1 0 >= x >= y x y 1 0 == x == y x y 1 0!= x!= y x y 1 0 == = == = (exclusive OR) A B A B 3.4 if switch if...else if ( ) [else ] else 14

18 C 3 { } 11 if... else main x 0 True 0 False 8 ex11.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : double x; 8 : 9 : x = atof(argv[1]); 10 : printf("x = %g --> ", x); 11 : if (x) { 12 : printf("true\n"); 13 : } else { 14 : printf("false\n"); 15 : } 16 : return (0); 17 : } 0 $ gcc -o ex11 ex11.c -lm $./ex x = > True $./ex x = 0 --> False $./ex11 1e-500 x = 0 --> False $./ex11 1e-200 x = 1e > True $./ex11 a x = 0 --> False if (x) printf("true\n"); if (!x) printf("false\n"); 2 if 2 if 1 x x!=0 10 x x 3 True False P x, y P (2,3) 2 q11.c 12 2 x, y x y x, y 9 ex12.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : double x, y; 8 : 9 : x = atof(argv[1]); 10 : y = atof(argv[2]); 11 : printf("(%4.2f,%4.2f) --> ", x, y); 12 : 13 : if (x > 0) { 14 : if (y > 0) { 15 : printf("1st quadrant\n"); 16 : } else if (y == 0) { 17 : printf("x-axis\n"); 18 : } else 19 : printf("4th quadrant\n"); 20 : } else if (x == 0) { 21 : if (y > 0 y < 0) { 22 : printf("y-axis\n"); 23 : } else 24 : printf("origin\n"); 25 : } else { /* x < 0 */ 26 : if (y > 0) { 27 : printf("2nd quadrant\n"); 28 : } else if (y == 0) { 29 : printf("x-axis\n"); 30 : } else 31 : printf("3rd quadrant\n"); 32 : } 33 : return (0); 34 : } [ ] ex12.c ex12u.c 15

19 C 3 $./ex (1.00,0.00) --> x-axis $./ex (0.00,0.00) --> origin $./ex (-2.00,-3.00) --> 3rd quadrant [ ] ex13.c argv[1][0] argv[1] 1 8 inputc scanf(" %c", &c) scanf 1 "%c" 3.5 switch...case if... else switch... case switch () { case 1 : 1 [break;] case 2 : 2... default : d } ; : case default: case break; 13 a, A alive d, D dead other switch... case 10 ex13.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : char inputc; 8 : inputc = argv[1][0]; 9 : 10 : switch (inputc) { 11 : case A : break; 12 : case a : 13 : printf("alive\n"); 14 : break; 15 : case D : break; 16 : case d : 17 : printf("dead\n"); 18 : break; 19 : default: 20 : printf("other\n"); 21 : break; 22 : } 23 : return (0); 24 : } %c " %c" $./ex13 D dead $./ex13 a alive $./ex13 p other 12 if... else q12.c x, y k (x + y)/2 j xy b q13.c 1 (charcter constant) int A x41 2 GCC abc sizeof 11 notes3-5.c 4 : 5 : int main(void) 6 : { 7 : int s = abc ; 8 : printf("size = %d\n", sizeof(s)); 9 : printf("%#x\t%d\n", s, s); 10 : return (0); 11 : } size 4 (long) int 16

20 C 3 1byte $ gcc -o charconst -Wall charconst.c charconst.c: In function main : charconst.c:7: warning: multi-character character constant $./charconst size = 4 0x if... else a? b : c a b c a c b if... else b c ex14.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : int i = atoi(argv[1]), n; 8 : 9 : printf("%d --> ", i); 10 : n = i? printf("true\n") : printf("false\n"); 11 : printf("printed characters = %d\n", n); 12 : 13 : return (0); 14 : } printf() True \n 5 6 $./ex > True printed characters = 5 $./ex > False printed characters = x y P(x, y) OAB O A B (0,0) (1,0) (0,2) 17 ax 2 + bx + c = 0 q17.c 1fefefefefefefefefefefe1 > >= < <= ==!=! && if... [else] switch... case a? b : c switch... case case 1fefefefefefefefefefefe if... else 17

21 C 4 LOOP 4 loop while while +... while () 15 imax 10 imax i i 2 13 ex15.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : int i, imax = atoi(argv[1]); 8 : i 9 : i = 10; 10 : while (i <= imax) { 11 : printf("i = %3d\t i**2 = %5d\n", i, i * i); 12 : i++; 13 : } 14 : 15 : return (0); 16 : } i [ ] while ex15.c i++ ++ i 1 increment operator 1 -- decrement operator 11 * x * y xy / x / y x/y + x + y x + y - x - y x y % x % y x mod y x,y ++ ++x, x++ x x, x-- x 1 postfix notation prefix notation 1 ++i --ii+1 i-1 i++ i--i i 1 (simple assignment operator) i = i+1; (compound assignment operator) i += 1; $./ex i = 10 iˆ2 = 100 i = 11 iˆ2 = 121 i = 12 iˆ2 = i = 99 iˆ2 = 9801 i = 100 iˆ2 = $./ex15 9 $ 18

22 C 4 LOOP i=10 i++ /* */ do...while do... while while do while (); ex16.c do... while 4 : 5 : int main(int argc, char **argv) 6 : { 7 : int i, imax = atoi(argv[1]); 8 : 9 : i = 10; 10 : do { 11 : printf("i = %3d\t i**2 = %5d\n", i, i * i); 12 : i++; 13 : } while (i <= imax); 14 : 15 : return (0); 16 : } 1 10 i=10 do... while $./ex16 9 i = 10 iˆ2 = for for 3 for (; ; ) while ex17.c while do... whlie for 4 : 5 : int main(int argc, char **argv) 6 : { 7 : int i, imax; 8 : 9 : imax = atoi(argv[1]); 10 : for (i = 10; i <= imax; i++) { 11 : printf("i = %3d\t i**2 = %5d\n", i, i * i); 12 : } 13 : return (0); 14 : } [ ] ex17.c for (x64) 16 ex18.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : int i, j, n; 8 : 9 : for (i = 0; i < 16; i++) { 10 : for (j = 0; j < 8; j++) { 11 : n = 8 * i + j; 12 : printf("%3d(x%02x) ", n, n); 13 : } 14 : printf("\n"); 15 : } 16 : 17 : return (0); 18 : } 19

23 C 4 LOOP 19 q19.c 4.3 C break continue goto return break switch... case switch... case return ( ) break break switch... case while () { }... break; switch () { }... break; do... while for 19 q Q 17 ex19.c 4 : 5 : int main(void) 6 : { 7 : char c; 8 : 9 : while (1) { 10 : printf("input a character "); 11 : scanf(" %c", &c); 12 : if (c == q c == Q ) { 13 : break; 14 : } 15 : printf("%c\n", c); 16 : } 17 : printf("now quit\n"); 18 : return (0); 19 : } [ ] ex19.c $./ex19 Input a character a a Input a character 1 1 Input a character Q Now quit $ [] ex19b.c break while = 10, 11, 12, 9 q, Q 18 ex19b.c 4 : 5 : int main(void) 6 : { 7 : char c; 8 : 9 : while (c!= q && c!= Q ) { 10 : printf("input a charactor "); 11 : scanf(" %c", &c); 12 : printf("%c\n", c); 13 : } 14 : printf("now quit\n"); 15 : return (0); 16 : } A B!A &&!B 9 $./ex19b Input a charactor Q Q Q Now quit $ 20 while switch... case while q20.c 20

24 C 4 LOOP continue continue while for while () { }... continue; do {... continue;... } while () ;... break c C continue 19 ex20.c 4 : 5 : int main(void) 6 : { 7 : char c; 8 : 9 : while (1) { 10 : printf("input a charactor "); 11 : scanf(" %c", &c); 12 : if (c == c c == C ) { 13 : continue; 14 : } else if (c == q c == Q ) { 15 : break; 16 : } 17 : printf("%c\n", c); 18 : } 19 : printf("now quit\n"); 20 : return (0); 21 : } [ ] ex20.c goto goto goto 21 continue if... else swicth... case break while goto 20 ex21.c 4 : 5 : int main(void) 6 : { 7 : char c; 8 : 9 : while (1) { 10 : printf("input a charactor "); 11 : scanf(" %c", &c); 12 : switch (c) { 13 : case c : 14 : case C : break; 15 : 16 : case q : 17 : case Q : printf("now quit\n"); 18 : goto QUIT; 19 : 20 : default : printf("%c\n", c); 21 : break; 22 : } 23 : } 24 : QUIT: 25 : return (0); 26 : } [ ] ex21.c return return return ; retrun value ( ) C

25 C 4 LOOP q22.c 22 1e-5 ( ) ex22.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : int i = 0, lmax; 8 : double dd = 1e-5, s, id; 9 : 10 : printf("dd = %.15f\n", dd); 11 : printf("lmax = %d\n", lmax = 1 / dd); 12 : for (s = 0; s <= 1.0; s += dd) { 13 : id = i * dd; 14 : if (i > lmax - 3) { 15 : printf("%6d, %.15f, %.15f\n", i, s, id); 16 : } 17 : i++; 18 : } 19 : return (0); 20 : } 1fefefefefefefefefefefe1 (loop) 3 while () do while (); for (; ; ) break, continue, goto 1fefefefefefefefefefefe1 $./ex22 dd = lmax = , , , , , , , , /(1e-5) e e-5 n ne-5 (n 10 5 ) 21 1 n 2 n k=1 k 2 = 1 n(n + 1)(2n + 1) 6 q21.c 22 e x e x x k = c k (x) = k! = 1 + x + x2 2! + x3 3! + k=0 k=0 x c k (x) < 1e-15 ( ) exp(x) 22

26 C 5 5 array []; double x[128]; double 128 x[0], x[1], x[2], x[3]... subscript [ ] subscript operator 0 i [i-1] N N 1 N int N = 5; double x[n]; ANSI C99 GCC ANSI C = x[0] = 0.12; x[2] = 2*x[0] + x[1]; x[k] = x[i]*x[j]; double ax[50], ay[50]; ax = ay; 5.2 double x[3] = {0.1, 0.3, 0.5}; int kx[4] = {1, 2, 3, 4}; char str[6] = { H, e, l, l, o }; 0 GCC char 1 double x[2]; x[3] = {0.1, 0.2}; x = {0.1, 0.2}; double x[] = {0.1, 0.3, 0.5}; int kx[] = {1, 2, 3, 4, 5, 6}; char str[] = { W, o, r, l, d }; kx

27 C RAND_MAX rand() srand(seed) 22 ex23.c 4 : #include <time.h> 5 : 6 : int main(int argc, char **argv) 7 : { 8 : int i, xi[16]; 9 : 10 : srand(time(null)); 11 : for (i = 0; i < 16; i++) { < : xi[i] = rand() % 10; 13 : printf("xi[%2d] = %d\n", i, xi[i]); 14 : } 15 : return (0); 16 : } matrix2 M N A A[M][N] i, j A[i][j] A[M][N] N M A[i] i i + 1 N A[i][j] = (A[i])[j] i i + 1 j j N 2 1 N 23 ex24.c [ ] ex23.c 11 rand() % 0 9 srand(seed) seed srand() :00:00 UTC time(null) NULL $./ex23 xi[ 0] = 9 xi[ 1] = 9 xi[ 2] = 0... xi[15] = 2 $./ex23 xi[ 0] = 6 xi[ 1] = 3 xi[ 2] = 8... xi[15] = : #include <time.h> 5 : 6 : #define N 4 7 : 8 : int main(int argc, char **argv) 9 : { 10 : int i, j, n, A[N][N]; 11 : 12 : srand(time(null)); 13 : for (i = 0; i < N; i++) { 14 : for (j = 0; j < N; j++) { 15 : A[i][j] = -1; 16 : } 17 : } 18 : 19 : for (n = 0; n < N * N; n++) 20 : while (1) { 21 : i = rand() % N; 22 : j = rand() % N; 23 : if (A[i][j] == -1) { 24 : A[i][j] = n; 25 : break; 26 : } 27 : } 28 : 29 : for (i = 0; i < N; i++) { 30 : for (j = 0; j < N; j++) 31 : printf("%2d ", A[i][j]); 32 : printf("\n"); 33 : } 34 : 35 : return (0); 36 : } [ ] ex24.c 6 N #define N 4 N 4 # #include 24

28 C N ex24u.c N = $./ex $./ex q25.c N M 2 NM [ ] ex25.c 15,20 &A[i][j] & A[i][j] address: scanf() %p &x 16 (long) int 4 4 ex25.c 24 ex25.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : int i, j; 8 : int B[3][3] = 9 : { 10 : {8, 7, 6}, 11 : {5, 4, 3}, 12 : {2, 1, 0}}; 13 : int A[9] = 14 : {8, 7, 6, 5, 4, 3, 2, 1, 0}; 15 : 16 : 17 : printf("one dimensional array\n"); 18 : for (i = 0; i < 3; i++) 19 : for (j = 0; j < 3; j++) 20 : printf("%d ==> %p\n", A[3 * i + j], &A[3 * i + j]); 21 : 22 : printf("two dimensional array\n"); 23 : for (i = 0; i < 3; i++) 24 : for (j = 0; j < 3; j++) 25 : printf("%d ==> %p\n", B[i][j], &B[i][j]); 26 : 27 : return (0); 28 : } $./ex25 One dimensional array 8 ==> 0xbffff94c 7 ==> 0xbffff950 6 ==> 0xbffff954 5 ==> 0xbffff958 4 ==> 0xbffff95c 3 ==> 0xbffff960 2 ==> 0xbffff964 1 ==> 0xbffff968 0 ==> 0xbffff96c Two dimensional array 8 ==> 0xbffff970 7 ==> 0xbffff974 6 ==> 0xbffff978 5 ==> 0xbffff97c 4 ==> 0xbffff980 3 ==> 0xbffff984 2 ==> 0xbffff988 1 ==> 0xbffff98c 0 ==> 0xbffff990 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] B[0][0] B[0][1] B[0][2] B[1][0] B[1][1] B[1][2] B[2][0] B[2][1] B[2][2] p

29 C 5 26 USHRT_MAX n n 25 ex26.c 4 : #include <limits.h> 5 : 6 : int main(int argc, char **argv) 7 : { 8 : int i, n, flag ; 9 : int prime[ushrt_max] = {2,3}, ptr = 2; 10 : 11 : for (n = 5; n < USHRT_MAX ; n += 2) { 12 : flag = 1; default 13 : for (i = 1; prime[i]*prime[i] <= n; i++) { 14 : if (n % prime[i] == 0){ 15 : flag = 0; 16 : break; for 17 : } 18 : } 19 : if (flag) { 20 : prime[ptr] = n; 21 : ptr++; 22 : } 23 : } 24 : 25 : for (i = 0; i < ptr; i++) { 26 : printf("%5d, ",prime[i]); 27 : } 28 : printf("\n%d\n", ptr); 29 : return (0); 30 : } [ ] ex26.c unsigned short int USHRT_INT limits.h 32bit CPU GCC 65,535 (=1) flag 12 flag = flag ex26u.c 11 n += 2 (compound assignment operator) n + n 2 11 op x op= y x op= y x = x op y x += 1 x = x + 1 x /= a x = x / a i %= 8 i = i % 8 x [k, k + ] h[k] x 27 [0,1) drand48() ( 0.5) R N = r 1 + r r r i [0, 1) 26 ex27.c 4 : #include <time.h> 5 : 6 : #define N 20 7 : 8 : int main(int argc, char **argv) 9 : { 10 : int i, imax, j, xi[n + 1] = 11 : {0}; 12 : double s; 13 : 14 : imax = atoi(argv[1]); 15 : srand48(time(null)); drand48() 16 : for (i = 0; i < imax; i++) { 17 : s = 0; 18 : for (j = 0; j < 12; j++) { 19 : s += drand48(); 20 : } 21 : s /= 12; 22 : xi[(int) floor(s * N)] += 1; 23 : } 24 : for (i = 0; i < N; i++) { 25 : printf("[%.2f:%.2f] = %6d\n", 26 : (i + 0.0) / N, (i + 1.0) / N, xi[i]); 27 : } 28 : return (0); 29 : } [ ] ex27.c 26

30 C 5 21 (int).. (cast operator) (int) C 25 (i+0.0)/n i/n / (double)i/n ex27.c $./ex [0.00:0.05] = 0 [0.05:0.10] = 0 [0.10:0.15] = 4 [0.15:0.20] = 83 [0.20:0.25] = 889 [0.25:0.30] = 6686 [0.30:0.35] = [0.35:0.40] = [0.40:0.45] = [0.45:0.50] = [0.50:0.55] = [0.55:0.60] = [0.60:0.65] = [0.65:0.70] = [0.70:0.75] = 6549 [0.75:0.80] = 901 [0.80:0.85] = 66 [0.85:0.90] = 2 [0.90:0.95] = 0 [0.95:1.00] = 0 drand48 : GCC drand drand48 rand 26 * 1 50 q26.c $./q [0.00:0.05] = [0.05:0.10] = [0.10:0.15] = [0.15:0.20] = [0.20:0.25] = [0.25:0.30] = * [0.30:0.35] = ****** [0.35:0.40] = ***************** [0.40:0.45] = *********************************** [0.45:0.50] = ************************************************** [0.50:0.55] = ************************************************* [0.55:0.60] = *********************************** [0.60:0.65] = ***************** [0.65:0.70] = ****** [0.70:0.75] = * [0.75:0.80] = [0.80:0.85] = [0.85:0.90] = [0.90:0.95] = [0.95:1.00] = 1fefefefefefefefefefefe1 double x[50]; x[1] = 1.0; double x[2]={2e-3, 0.1}; int dd[]={3, 4, 5, 9} double A[6][7]; int C[2][3][3]; 1fefefefefefefefefefefe1 man 3 rand Mersenne Twister Home Page 27

31 C 6 6 C main library function inline C99 inline C void () () void double funcz(double) void funcv(char, double, double) funcz double 1 double funcv char 1 double 2 () { return ; void } 6.2 printf atof atof () pass by value double funcz(double z) double funcz(double z) { z z } int main(void) {... funcz(1.2); 1.2 z... x = 2.0; funcz(x); x 2.0 z funcz(x*x); x*x 4.0 z... } 28 2 main [ ] ex28.c 15 main exit() argv[0] 7,8 return 28

32 C 6 $./ex $./ex28-61./a.out x y 27 ex28.c 4 : 5 : double bigone(double s, double t) 6 : { 7 : if (s >= t) 8 : return (s); 9 : else 10 : return (t); 11 : } 12 : 13 : int main(int argc, char **argv) 14 : { 15 : double x, y; 16 : 17 : if (argc < 3) { 18 : printf(" %s x y\n", argv[0]); 19 : exit(0); 20 : } 21 : x = atof(argv[1]); 22 : y = atof(argv[2]); 23 : printf(" %g %g ", x, y); 24 : printf(" %g \n", bigone(x, y)); 25 : 26 : return (0); 27 : } 27 main q27.c kterm main kterm xterm \E[H\E[2J \E ASCII ESC x1b [ ] ex29.c clr main infocmp clear=xxx XXX man terminfo libcurses Linux libncurses 28 ex29.c 4 : 5 : void clr(void) 6 : { 7 : char clear[8] = 8 : {27, [, H, 27, [, 2, J }; 9 : printf("%s", clear); 10 : } 11 : 12 : int main(int argc, char **argv) 13 : { 14 : clr(); 15 : return (0); 16 : } 28 n - n q28.c 6.4 scanf() & v &v return 12 29

33 C x x &x A A[ ] A &A f f( ) f &f A[ ] A 1 &A[0] 30 main ex30u.c [ ] ex30.c maxof() 29 ex30.c 4 : #include <time.h> 5 : 6 : #define N 8 7 : 8 : int maxof(int a[], int imax) 9 : { 10 : int i, max = a[0]; 11 : 12 : for (i = 0; i < imax; i++) { 13 : if (a[i] >= max) 14 : max = a[i]; 15 : } 16 : return (max); 17 : } 18 : 19 : int main(int argc, char **argv) 20 : { 21 : int i, a[n]; 22 : 23 : srand(time(null)); 24 : for (i = 0; i < N; i++) { 25 : a[i] = rand() % 10000; 26 : if (i < N - 1) { 27 : printf("%4d,", a[i]); 28 : } else 29 : printf("%d\n", a[i]); 30 : } 31 : 32 : printf(" %d \n", maxof(a, N)); 33 : 34 : return (0); 35 : } $./ex , 1820, 2778, 4315, 676, 3435, 6270, z &z double *x x x main [ ] ex31.c 30 ex31.c 4 : 5 : void one(double *x) 6 : { 7 : *x = 1.0; 8 : } 9 : 10 : int main(int argc, char **argv) 11 : { 12 : double z = 10.0; 13 : 14 : printf("z = %f\n", z); 15 : one(&z); 16 : printf("z = %f\n", z); 17 : 18 : return (0); 19 : } 5 7 x main z x = &z z *x = *(&z) = z 15 one() z &z * * ptr *ptr ptr 30

34 C 6 x &x x *&x = x x *x 29 2 q29.c 30 main q30.c max, min void maxminof(int a[], int imax, int *max int *min) 6.5 recursive 32 [ ] ex32.c 31 ex32.c 4 : 5 : double fact(double x) 6 : { 7 : if (x > 1) { 8 : return (x * fact(x - 1)); 9 : } else { 10 : return (x); 11 : } 12 : } 13 : 14 : int main(int argc, char **argv) 15 : { 16 : int i; 17 : 18 : for (i = 1; i <= 25; i++) { 19 : printf("fact(%2d) = %.0f\n", i, fact(i)); 20 : } 21 : 22 : return (0); 23 : } $./ex32 fact( 1) = 1 fact( 2) = 2 fact( 3) = 6 fact( 4) = 24 fact( 5) = 120 fact( 6) = 720 fact( 7) = fact(19) = fact(20) = fact(21) = fact(22) = fact(23) = fact(24) = fact(25) = long double n Stiring log n! n log n n q31.c gp ! 33 n log(n!) n log n n f (x) [a, b] x i x i+1 f (x i ) 7 7 x i+1 x i = h = (b a)/n b a n 1 f (x) dx = h f (x i ) i=0 31

35 C 6 cos(x) [a, b] a, b n a = 0 b = x sin(x) [ ] ex33.c 32 ex33.c 4 : 5 : void hline(int len) 6 : { 7 : for (; len > 0; len--) 8 : printf("-"); 9 : printf("\n"); 10 : } 11 : 12 : double integ_cos(double a, double b, int n) 13 : { 14 : int i; 15 : double sum = 0, dx = (b - a) / n; 16 : 17 : for (i = 0; i < n; i++) 18 : sum += cos(a + i * dx) * dx; 19 : return (sum); 20 : } 21 : 22 : int main(int argc, char **argv) 23 : { 24 : int i, N = atoi(argv[1]); 25 : double x, numeric, err; 26 : 27 : hline(45); 28 : printf("x\t\tinteg[cos(x)]\terror\n"); 29 : hline(45); 30 : for (i = 0; i <= 32; i++) { 31 : x = 2 * M_PI / 32 * i; 32 : numeric = integ_cos(0, x, N); 33 : err = numeric / sin(x) - 1; 34 : printf("%.6f\t%+.6f\t%+.4e\n", x, numeric, err); 35 : } 36 : hline(45); 37 : 38 : return (0); 39 : } integ_cos() line() N main 35 = ( )/ x = 0, π, 2π sin(x) = 0 ex33u.c $./ex x int[cos(x)] error nan e e e e e e e e e x i x i + h/2 q32.c 33 f (x) d f dx = lim f (x + h) f (x) h 0 h h x 3 dx3 dx = 3x2 6.6 C GNU GCC GNU C99 GCC /usr/include/math.h /usr/include/bits/mathcall.h man C99 USE_ISOC99 GNU USE_GNU #define USE_ISOC99 1 #define USE_GNU 1 #include <math.h> 32

36 C 6 15 double GCC 13 int C rand() 0 RAND_MAX srand(seed) rand( ) seed unsignedint void abs(n) n div(n,m) n/m div_t quot rem int random() rand() BSD4.3 srandom(seed) random() BSD4.3 C rint(x) C99 copysign(x,y) C99 drem(x,y) drand48() srand48() j0(x), j1(x), jn(n,x) y0(x), y1(x), yn(n,x) asinh(x) C99 acosh(x) C99 atanh(x) C99 x y x y [0.0, 1.0) n n arcsinh(x), arccosh(x) arctanh(x) cbrt(x) C99, hypot(x,y) C99 3 x, (x 2 + y 2 ) 1/2 expm1(x) C99, log1p(x) C99 e x 1, log(x + 1) lgamma(x) C99 log Γ(x) erf(x) C99 erfc(x) C99 Erf(x) 2 x e t2 dt π Erfc(x) 1 Erf(x) 0 1fefefefefefefefefefefe1 14 double C sin(x),cos(x),tan(x) sin(x), cos(x), tan(x) asin(x),acos(x) arccos(x), arcsin(x) atan(x), atan2(y, x) arctan(x), arctan(y/x) sinh(x),cosh(x),tanh(x) sinh(x), cosh(x), tanh(x) pow(x,y), sqrt(x) x y, x exp(x) frexp(x, *n) ldexp(x, n) log(x), log10(x) ceil(x), floor(x) fabs(x) fmod(x,y) modf(x,*y) e x y, n 2 n y = x ( 1 2 y < 1) 2 n x n log e (x) log 10 (x) x, x x x y x, y x 1fefefefefefefefefefefe1 33

37 C 7 7 C int double C 7.1 char char \0 \0 char abc[4]; char message[5] = { G, o, o, d, \0 }; char greeting[] = "Hello!" ; N char N + 1 greeting 6(Hello!)+1( \0 ) = 7 char abc a[0]= a ; a[1]= b ; a[2]= c ; a[3]= \0 ; 1 34 a[0] a[1] a[2] a[3] a b c \0 [ ] ex34.c 33 ex34.c 3 : 4 : int main(int argc, char **argv) 5 : { 6 : int i, len; 7 : char str[] = "A quick brown fox jumps" 8 : " over the lazy dog"; 9 : 10 : printf("str = %s \n", str); 11 : len = sizeof(str) - 1; 12 : 13 : for (i = 0; i < len; i++) { 14 : printf("[%c]", str[i]); 15 : } 16 : printf("\n"); 17 : 18 : str[10] = \0 ; 19 : printf("str = %s \n", str); 20 : str[10] = ; 21 : printf("str = %s \n", str); 22 : str[len] = + ; 23 : printf("str = %s \n", str); 24 : 25 : return (0); 26 : } 7,8 2 C 1 10 printf %s char 11 char sizeof char 1-1 ( \0 ) [ ] 18 printf %s 22 printf $./ex34 str = A quick brown fox jumps over a lazy dog. [A][ ][q][u][i][c][k][ ][b][r][o][w][n][ ]... str = A quick br str = A quick br wn fox jumps over a lazy = A quick br wn fox jumps over a lazy dog.+ 34

38 C 7 A quick brown... pangram \0 1 int length i = 0; while (A[i]!= \0 ){ } i++; length = i; strlen() $ man strlen STRLEN(3) Linux Programmer s Manual STRLEN(3) strlen - #include <string.h> size_t strlen(const char *s); strlen() s \0 strlen() s SVID 3, POSIX, BSD 4.3, ISO 9899 string(3) April 12, size_t unsigned int string man strcasecmp, strcat, strchr, strcmp, strcoll, strcpy, strcspn, strdup, strfry, strlen, strncat, strncmp, strncpy, strncasecmp, strpbrk, strrchr, strsep, strspn, strstr, strtok, strxfrm, index, rindex copy duplicate source destination dest char dest[128] = { \0 }; char src[] = "source strings";... i = 0; while ( src[i]!= \0 ) { } dest[i] = src[i]; i++; dest[i] = \0 ;... strcpy() strncpy() man strcpy char *strcpy(char *dest, const char *src); char *strncpy(char *dest, const char *src, size_t n); A[ ] A dest src compare man ascii ascii 35

39 C 7 A z char [A-Z][a-z] s1 s2 i = 0; while (s1[i] == s2[i]) { } if (s1[i] == \0 ) break; i++; result = (int)s1[i] - (int)s2[i]; result result 0 0, 0 s1 s2 ascii C char ctype.h include isalpha(c) islower(c) isupper(c) isdigit(c) isxdigit(c) isalnum(c) isprint(c) isgraph(c) isspace(c) ispunct(c) iscntrl(c) inblank(c) C99 isascii(c) ! #$ 7bit ASCII int true/false c char int BSD SVID GCC 17 / ( ) 35 strlen(), strcpy(), 17 / tolower(c) toupper(c) strcmp() mystrlen(), mystrcpy(), mystrcmp() [ ] ex35u.c 34 ex35.c 2 : #include <string.h> 3 : 4 : int mystrlen(char a[]) 5 : { 6 : int i = 0; 7 : 8 : while (a[i]!= \0 ) { 9 : i++; 10 : } 11 : return i; 12 : } 13 : 14 : int mystrcmp(char s1[], char s2[]) 15 : { 16 : int i = 0; 17 : 18 : while (s1[i] == s2[i]) { 19 : if (s1[i] == \0 ) 20 : break; 21 : i++; 22 : } 23 : return ((int) s1[i] - (int) s2[i]); 24 : } 25 : 26 : void mystrcpy(char dest[], char src[]) 27 : { 28 : int i = 0; 29 : 30 : while (src[i]!= \0 ) { 31 : dest[i] = src[i]; 32 : i++; 33 : } 34 : dest[i] = \0 ; 35 : } 36 : 37 : int main(void) 38 : { 39 : char src[] = "Dog as a devil deified," 40 : " lived as a god"; 41 : char cmp[] = "Dog as a devil deified,"; 42 : char dest[80] = 43 : { \0 }; 44 : 45 : printf("%d, %d\n", mystrlen(cmp), strlen(cmp)); 46 : printf(" %s \n", dest); 47 : mystrcpy(dest, src); 48 : printf(" %s \n", dest); 49 : 50 : printf("%d, %d\n", mystrcmp(cmp, src), 51 : strcmp(cmp, src)); 52 : 53 : return (0); 54 : } 36

40 C 7 my $./ex35 23, 23 Dog as a devil deified, lived as a god -32, (10) 32 (10) 34 strcmp() strcasecmp() mystrcasecmp() q34.c 7.3 scanf() 1 getchar() putchar() 36 1 getchar(), putchar() BEL= \a [ ] ex36.c 35 ex36.c concatenate $a = " " C $b = "" $c = $a+$b C C strcat() cat concatenate char *strcat(char *dest, const char *src); dest src dest \0 src dest src 35 mystrcat() strcat() q35.c strchr, strrchr, index, rindex 1 1 strpbrk, strstr 2 : 3 : #define QUIT \a /* ascii BEL */ 4 : 5 : int main(void) 6 : { 7 : int ch; 8 : 9 : while ((ch = getchar())!= QUIT) { 10 : putchar(ch); 11 : } 12 : 13 : return (0); 14 : } 9 getchar() 1 unsigned char int int ch 10 putchar(ch) BEL= \a kterm Ctrl+G while $./ex36 abcdefghijklm!"#$%& () abcdefghijklm!"#$%& () ˆG BEL $ 36? q36.c 7.4 \n EOF (end of file) gets() puts() fgets(),fputs() 37

41 C 7 gets() fgets() man fgets() char *fgets(char *s, int size, FILE *stream); size - 1 FILE *stream stdin 37 fgets() 80 [ ] ex37.c fgets() 1fefefefefefefefefefefe1 C char \0 \0 char 1fefefefefefefefefefefe1 36 ex37.c 3 : #include <string.h> 4 : 5 : #define BUFSIZE 81 6 : 7 : int main(void) 8 : { 9 : int len, i; 10 : char buf[bufsize]; 11 : 12 : while (fgets(buf, BUFSIZE, stdin)!= NULL) { 13 : len = strlen(buf); 14 : for (i = len - 2; i >= 0; i--) { 15 : putchar(buf[i]); 16 : } 17 : putchar( \n ); 18 : } 19 : 20 : return (0); 21 : } stdin fgets() \n 14 (len-1)-1 $./ex37 Dog as a devil deified, lived as a god dog a sa devil,deified lived a sa god Madam I m adam mada m I madam $ Ctrl + d Ctrl + d Ctrl 37 + c q37.c 38

42 C 8 8 C C x x &x &x x a a[ ] &a &a a f f( ) &f &f f a a[ ] a (=&a[0]) a (=&a[0]) a[0] p *p &p p A (*A)[ ] &A A F (*F)( ) &F F &x *(&x) = x 8.2 & * P O * *P O *P alias P 0x... 0x1234 O 0x1234 O *P = *0x1234 = 0x1234 = O *address = address *, [ ], ( ) 3 * ( ), [ ] ( ) (*A)[] (*f)() *A[] *f() 8.1 & double x, y, a[10]; &x = &y; &x = &a[1]; &a[1] = &x; a = &x; 8.3 a *a a[0] &a a *&a *a f(); f &f * 39

43 C sizeof char a[10]; char 1 sizeof(a) OS Segmentation Fault double *px; double *px = 1.0; *px = 1.0; *px = 1.0; px px &px px * double rx; rx double *px; px = &rx; px rx *px = 1.0; *px(=rx) (i) (ii) alias [ ] ex38.c 37 ex38.c 4 : 5 : double f(double x) 6 : { 7 : return (x * 100.0); 8 : } 9 : 10 : int main(int argc, char **argv) 11 : { 12 : double x = 1, a[3] = 13 : {10, 20, 30}, f(); 14 : double *px, (*pa)[3], (*pf) (); 15 : 16 : printf("&x = %p, *(&x) = %f\n", &x, *(&x)); 17 : printf("&a = %p, *(&a) = %p\n", &a, *(&a)); 18 : printf("&f = %p, *(&f) = %p\n", &f, *(&f)); 19 : printf("a = %p, *a = a[0] = %f\n", a, a[0]); 20 : px = &x; 21 : pa = &a; 22 : pf = &f; 23 : printf("px = %p, *px = %f\n", px, *px); 24 : printf("pa = %p, *pa = %p\n", pa, *pa); 25 : printf("pf = %p, *pf = %p\n", pf, *pf); 26 : 27 : printf("(*pf)(3.1) = %f\n", (*pf) (3.1)); 28 : printf("(*pa)[1] = %f\n", (*pa)[1]); 29 : 30 : return (0); 31 : } px, pa, pf x, a, f *px = x, (*pa) = a, (*f) = f $./ex38 &x = 0xbffff9a4, *(&x) = &a = 0xbffff98c, *(&a) = 0xbffff98c &f = 0x80483f0, *(&f) = 0x80483f0 a = 0xbffff98c, *a = a[0] = px = 0xbffff9a4, *px = pa = 0xbffff98c, *pa = 0xbffff98c pf = 0x80483f0, *pf = 0x80483f0 (*pf)(3.1) = (*pa)[1] = double rx; rx double *px = &rx; *px = 1.0; *px(=rx) C 40

44 C 8 Fortran N N #define [ ] ex39.c ex39u.c 38 ex39.c 3 : #include <time.h> 4 : 5 : #define N 32 6 : 7 : void stat(int a[], int n, int *max, 8 : int *min, double *av) 9 : { 10 : int i, sum = 0; 11 : 12 : *max = *min = a[0]; 13 : for (i = 0; i < n; i++) { 14 : if (a[i] >= *max) 15 : *max = a[i]; 16 : if (a[i] <= *min) 17 : *min = a[i]; 18 : sum += a[i]; 19 : } 20 : *av = (double) sum / n; 21 : } 22 : 23 : int main(int argc, char **argv) 24 : { 25 : int i, a[n], max, min; 26 : double average; 27 : 28 : srand(time(null)); 29 : for (i = 0; i < N; i++) { 30 : a[i] = rand() % 10000; 31 : printf("%4d, ", a[i]); 32 : if (i % 8 == 7) 33 : printf("\n"); 34 : } 35 : 36 : stat(a, N, &max, &min, &average); 37 : printf(" %4d ", max); 38 : printf(" %4d \n", min); 39 : printf(" %.2f \n", average); 40 : 41 : return (0); 42 : } $./ex , 5071, 7164, 9095, 1030, 737, 3476, 6708, 440, 8053, 8050, 5000, 4735, 262, 3360, 1014, 8256, 3403, 5090, 3094, 2355, 3828, 4471, 2290, 9320, 9938, 9885, 6550, 4653, 207, 1865, 8085, p p+1 p+2, p+3,... char 1 long int 4 double 8 *(p+1), *(p+2), *(p+3),... a[] a a[0] a+i a[i] &a[i] a+i = &a[i] *(a+i) = *(&a[i]) = a[i] a[i] (*(a+(i))) GCC CPU C -S #include <stdio.h> int main(void){ int a[5]; a[1]; return (0);} #include <stdio.h> int main(void){ int a[5]; *(a+1); return (0);} 41

45 C 8 -S s ****.s 40 [ ] ex40.c 39 ex40.c 4 : 5 : int main(int argc, char **argv) 6 : { 7 : int i; 8 : char ca[] = "xyz"; 9 : double xa[] = 10 : {1, 3, 5}; 11 : 12 : for (i = 0; i < 3; i++) { 13 : printf("(%p): ca[%d] = %c, *(ca+%d) = %c\n", 14 : ca + i, i, ca[i], i, *(ca + i)); 15 : } 16 : for (i = 0; i < 3; i++) { 17 : printf("(%p): xa[%d] = %.3f, *(xa+%d) = %.3f\n", 18 : xa + i, i, xa[i], i, *(xa + i)); 19 : } 20 : 21 : return (0); 22 : } $./ex40 (0xbffff9a4): ca[0] = x, *(ca+0) = x (0xbffff9a5): ca[1] = y, *(ca+1) = y (0xbffff9a6): ca[2] = z, *(ca+2) = z (0xbffff98c): xa[0] = 1.000, *(xa+0) = (0xbffff994): xa[1] = 3.000, *(xa+1) = (0xbffff99c): xa[2] = 5.000, *(xa+2) = char strlen() int strlen(char *s) { } char *p = s; while (*p!= \0 ) p++; retrun p - s; p++ p1, p2 p1 - p ( ) 2 main **argv 2 char argv argv char char 41 main char **argv char *argv[] 2 char [ ] ex41.c 42

46 C 8 40 ex41.c 3 : 4 : int main(int argc, char **argv) 5 : { 6 : char buf[10][128]; 7 : 8 : printf("argc: &buf\t &argv\t *buf[argc]\n"); 9 : while (argc-- > 0) { 10 : strcpy(buf[argc], argv[argc]); 11 : printf("%4d: %p %p %s\n", 12 : argc, buf[argc], argv[argc], buf[argc]); 13 : } 14 : 15 : return (0); 16 : } argc argv[argc] 2 buf (10) = 0x80 (16) argv ( +1) $./ex41 1 ABCDEFGHIJ argc: &buf &argv *buf[argc] 2: 0xbffff57c 0xbffffb1c ABCDEFGHIJ 1: 0xbffff4fc 0xbffffb1a 1 0: 0xbffff47c 0xbffffb13./ex41 0x80 (+1) 1fefefefefefefefefefefe1 a i a[i] = *(a+i) 1fefefefefefefefefefefe1 43

47 C struct struct [] { } [ ] ; club[0] = matuda; matuda club[0] club[1] = {"Namio Matuda", 46, 166}; strcpy(matuda.name,"mazda"); matuda.age = 50; club[1].age = matuda.age; scanf("%lf", &club[1].height); struct member { char name[40]; unsigned short int age; double height; } p1, p2; 3 name, age height member struct member p1 p2 struct member suzuki, satoh, oishi; struct member club[100], *who, func(); struct mmber struct member matuda = {"Namio Matuda", 46, 166}; 9.2 matuda (* ). -> -> struct member *who strcpy(who->name,"someone Else"); who->height = 203.2; printf("%.2f\n", who->height); 42 T m σ κ element.dat fgets(buffer, size, 44

48 C 9 stdin) command file $ command <file Unix OS [ ] ex42.c 41 ex42.c 4 : 5 : struct iccd { 6 : int number; 7 : char symbol[3]; 8 : char name[20]; 9 : double mt; 10 : double ec; 11 : double tc; 12 : }; 13 : 14 : void print(struct iccd p) 15 : { 16 : printf( 17 : "%2d %s\t%-8s\t%8.3f %8.2g %6.1f\n", 18 : p.number, p.symbol, p.name, p.mt, p.ec, p.tc 19 : ); 20 : } 21 : 22 : struct iccd getdat(char buf[]) 23 : { 24 : struct iccd p; 25 : sscanf(buf, "%d%s%s%lf%lf%lf", &p.number, 26 : p.symbol, p.name, &p.mt, &p.ec, &p.tc); 27 : return (p); 28 : } 29 : 30 : int main(void) 31 : { 32 : int i = 0; 33 : char buf[80]; 34 : struct iccd element[100]; 35 : 36 : while (fgets(buf, 80, stdin)!= NULL) { 37 : element[i] = getdat(buf); 38 : print(element[i]); 39 : i++; 40 : } 41 : return (0); 42 : } sscanf() return fgets 1 char buf getdat() buf print() ex42u.c $./ex42 < element.dat 3 Li Lithium e Be Beryllium e Na Sodium e Mg Magnesium e Al Aluminium e K Potassium e Tl Thallium e Pb Lead e Bi Bismuth e print() q38.c K q39.c 9.4 typedef struct typedef typedef unsigned short int USHRT; typedef struct {double x, y, z;] POINT3; USHRT unsigned short int 3 POINT3 USHRT i, j[100], f(...) POINT3 point *ppoint typedef struct {double x, y, z;} Vec3; Vec3 2 Vec3 vadd(vec3 v1, Vec3 v2) { Vec3 v; v.x = v1.x + v2.x; v.y = v1.y + v2.y; v.z = v1.z + v2.z; return (v); } 45

49 C 9 1 #include 3 vector.h vector.h 42 vector.h 4 : 5 : #define deg2rad(deg) ((deg)*m_pi/180) 6 : #define rad2deg(rad) ((rad)*180/m_pi) 7 : 8 : typedef struct {double x, y, z;} Vec3; 9 : typedef struct {double r, t, p;} Pol3; 10 : 11 : Vec3 vadd(vec3 a, Vec3 b) 12 : { 13 : Vec3 v; 14 : v.x = a.x + b.x; 15 : v.y = a.y + b.y; 16 : v.z = a.z + b.z; 17 : return (v); 18 : } 19 : 20 : Vec3 vsub(vec3 a, Vec3 b) 21 : { 22 : Vec3 v; 23 : v.x = a.x - b.x; 24 : v.y = a.y - b.y; 25 : v.z = a.z - b.z; 26 : return (v); 27 : } 28 : 29 : double viprod(vec3 a, Vec3 b) 30 : { 31 : return a.x*b.x + a.y*b.y + a.z*b.z; 32 : } 33 : 34 : Vec3 voprod(vec3 a, Vec3 b) 35 : { 36 : Vec3 c; 37 : c.x = a.y*b.z - a.z*b.y; 38 : c.y = a.z*b.x - a.x*b.z; 39 : c.z = a.x*b.y - a.y*b.x; 40 : return (c); 41 : } 42 : 43 : double vabs(vec3 a) 44 : { 45 : return sqrt(viprod(a,a)); 46 : } 47 : 48 : double varg(vec3 a, Vec3 b) 49 : { 50 : return acos(viprod(a,b)/(vabs(a)*vabs(b))); 51 : } 52 : 53 : Vec3 pol3tovec3(pol3 pv) 54 : { 55 : Vec3 v; 56 : v.x = pv.r*sin(pv.t)*cos(pv.p); 57 : v.y = pv.r*sin(pv.t)*sin(pv.p); 58 : v.z = pv.r*cos(pv.t); 59 : return (v); 60 : } voprod() c = a b a b = ( a y b z a z b y, a z b x a x b z, a x b y a y b x ) a b = a b sin θ θ a, b a, b 1 2 a b pol3tovec3() (r, θ, φ) (x, y, z) Pol3 Vec A,B,C ABC a, b, c [ ] ex43.c ex43u.c 43 ex43.c 4 : #include <time.h> 5 : #include "vector.h" 6 : 7 : int main(int argc, char **argv) 8 : { 9 : int i; 10 : double s1, s2, a, b, c, s; 11 : Vec3 v[3], va, vb, vc; 12 : 13 : srand(time(null)); 14 : for (i = 0; i < 3; i++) { 15 : v[i].x = rand() % 10; 16 : v[i].y = rand() % 10; 17 : v[i].z = rand() % 10; 18 : printf( 19 : "v[%d].x = %f, v[%d].y = %f, v[%d].z = %f\n", 20 : i, v[i].x, i, v[i].y, i, v[i].z 21 : ); 22 : } 23 : va = vsub(v[1], v[0]); 24 : vb = vsub(v[2], v[1]); 25 : vc = vsub(v[0], v[2]); 26 : a = vabs(va); 27 : b = vabs(vb); 28 : c = vabs(vc); 29 : s = (a + b + c) / 2; 30 : 31 : s1 = vabs(voprod(va, vb)) / 2; 32 : s2 = sqrt(s * (s - a) * (s - b) * (s - c)); 33 : printf(" 1 = %f, 2 = %f\n", s1, s2); 34 : 35 : return (0); 36 : } 40 xy a = b = c sin θ 1 sin θ 2 sin θ 3 θ 1, θ 2, θ 3 a, b, c q40.c 46

50 C 9 44 ex44.c a θ struct tm θ 3 c Unix UTC :00:00 time(null) man time struct tm struct tm { int tm_sec; /* */ int tm_min; /* */ int tm_hour; /* */ int tm_mday; /* */ int tm_mon; /* */ int tm_year; /* */ int tm_wday; /* */ int tm_yday; /* */ int tm_isdst; /* */ }; gmtime(), localtime() time_t now; struct tm *nowtm;... now = time(null); nowtm = localtime(&now) nowtime nowtm->hour 44 struct tm time() localtime() [ ] ex44.c b θ 1 2 : #include <time.h> 3 : 4 : int main(void) 5 : { 6 : time_t now; 7 : struct tm *nowtm; 8 : 9 : now = time(null); 10 : nowtm = localtime(&now); 11 : 12 : printf( 13 : " %d %02d %02d " 14 : " %02d:%02d:%02d.\n", 15 : nowtm->tm_year , nowtm->tm_mon + 1, nowtm->tm_mday, 16 : nowtm->tm_hour, nowtm->tm_min, nowtm->tm_sec 17 : ); 18 : printf("%s", ctime(&now)); 19 : 20 : return (0); 21 : } ctime() Unix usleep() <unistd.h> BSD ftime() <sys/timeb.h> notes9-6.c 45 notes9-6.c 3 : #include <unistd.h> 4 : #include <time.h> 5 : #include <sys/timeb.h> 6 : 7 : int main(int argc, char **argv) 8 : { 9 : struct tm *nowtm; 10 : struct timeb nowb; 11 : int interval = ; 12 : 13 : if (argc > 1) 14 : interval = atoi(argv[1]); 15 : while (1) { 16 : ftime(&nowb); 17 : nowtm = localtime(&nowb.time); 18 : printf("%02d:%02d %03d\n", 19 : nowtm->tm_min, nowtm->tm_sec, nowb.millitm); 20 : usleep(interval); 21 : } 22 : return (0); 23 : } ( µs) 0.3 s Ctrl + c $./a.out 19: : :

51 C C preprocessportability directive # #include #define #if #elif #else #endif #ifdef, #ifndef 10.1 #include #include <stdio.h> #include <math.h> #include "vector.h" <> "" 10.2 #define #define #define N N NN #define deg2rad(a) ((a)*m_pi/180) #define deg2rad(a) a*m_pi/180 deg2rad(x+1) 1/deg2rad(x) deg2rad(x+1) --> x+1*m_pi/180 1/deg2rad(x) --> 1/x*M_Pi/180 #define sqr(a) ((a)*(a)) sqr(x++) sqr(x++) --> ((x++)*(x++)) x++ 2 1fefefefefefefefefefefe1 struct struct [] { } []; typedef typedef 1fefefefefefefefefefefe1 48

52 C C C stream FILE FILE stdin stdoutstderr stdin stdout stderr fopen() FILE 11.1 FILE fopen() 19 fopen() mode mode "r" NULL "r+" + NULL "w" "w+" + "a" "a+" + r,r+,w,w+,a,a+ t b UNIX OS FILE fopen() FILE *fp; fp = fopen(name, mode); name char mode 19 NULL 11.2 : fclose() fclose(fp) fp fflush() fclose fp 20 int fgetc(fp) 1 EOF int getc(fp) 1 EOF int getchar() getc(stdin) EOF int ungetc(c,fp) 1 (c) EOF char *fgets(s,n,fp) 1 NULL char *gets(s) 1 NULL int fputc(c,fp) 1 (c) EOF int putc(c,fp) 1 (c) EOF int putchar(c) putc(c,stdout) EOF int fputs(s,fp) 1 EOF int puts(s) stdout 1 EOF fp c int s n int 11.4 fflush() fputc() fflush(fp) 45 element.dat 1 49

53 C ex45.c 4 : #include <unistd.h> 5 : 6 : int main(void) 7 : { 8 : int c; 9 : char infile[] = "element.dat"; 10 : FILE *fp; 11 : 12 : if ((fp = fopen(infile, "r")) == NULL) { 13 : printf("can t open %s\n", infile); 14 : exit(0); 15 : } 16 : while ((c = fgetc(fp))!= EOF) { 17 : fputc(c, stdout); 18 : fflush(stdout); 19 : usleep(100000); 20 : } 21 : fclose(fp); 22 : 23 : return (0); 24 : } [ ] ex45.c fopen() element.dat "r" fgetc(fp) 1 fputc(c,stdout) fgetc() getc() fputc() putc() 19,20 1 fflush() 1 usleep() Ctrl + c 11.5 printf() double e (Self-Discribing) HDF (Hierarchical Data Format) NetCDF (network Common Data Form) 11.6 fread() fwrite() fread() fwrite() size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) size_t fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream) fread() stream size nmemb ptr fwrite() ptr size nmemb stream void 46 2 [ ] ex46.c 22 double x fpc char.dat 23 fpb bin.dat x double 1 ex46u.c 2 $./ex46 $ ls -l char.dat bin.dat -rw-r--r :36 bin.dat -rw-r--r :36 char.dat bin.dat char.dat less char.dat 50

54 C 12 SYSTEM() 47 ex46.c 4 : 5 : int main(void) 6 : { 7 : double x; 8 : char filec[] = "char.dat"; 9 : char fileb[] = "bin.dat"; 10 : FILE *fpc, *fpb; 11 : 12 : if ((fpc = fopen(filec, "w+")) == NULL) { 13 : printf("can t open %s\n", filec); 14 : exit(0); 15 : } 16 : if ((fpb = fopen(fileb, "w+")) == NULL) { 17 : printf("can t open %s\n", fileb); 18 : exit(0); 19 : } 20 : for (x = 0; x < 1024; x++) { 21 : fprintf(fpc, "%.15f\n", x); 22 : fwrite(&x, sizeof(double), 1, fpb); 23 : } 24 : fclose(fpc); 25 : fclose(fpb); 26 : 27 : return (0); 28 : } q42.c fprintf() fscanf() fwrite() fread() q42.c 48 q42.c 4 : 5 : int main(void) 6 : { 7 : int i; 8 : double xc, xb; 9 : char filec[] = "char.dat"; 10 : char fileb[] = "bin.dat"; 11 : FILE *fpc, *fpb; 12 : 13 : if ((fpc = fopen(filec, "r")) == NULL) { 14 : printf("can t open %s\n", filec); 15 : exit(0); 16 : } 17 : if ((fpb = fopen(fileb, "r")) == NULL) { 18 : printf("can t open %s\n", fileb); 19 : exit(0); 20 : } 21 : for (i = 0; i < 1024; i++) { 22 : fscanf(fpc, "%lf\n", &xc); 23 : fread(&xb, sizeof(double), 1, fpb); 24 : printf("xc = %4.1f,\txb = %4.1f\n", xc, xb); 25 : } 26 : fclose(fpc); 27 : fclose(fpb); 28 : 29 : return (0); 30 : } 12 system() OS OS system() system() Unix /bin/sh -c system(" ") 47 sytem() cal 49 ex47.c 3 : 4 : int main(void) 5 : { 6 : system("/usr/bin/cal"); 7 : return (0); 8 : } $./ex

1 5 1.1.... 5 1.2................. 6 1.3............ 7 2 8 2.1.................... 8 2.1.1................ 8 2.2.................... 9 2.2.1................ 9 2.2.2............ 9 2.2.3 void................

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

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

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó  ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡ (2018) 2018 5 24 ( ) while ( ) do while ( ); for ( ; ; ) while int i = 0; while (i < 100) { printf("i = %3d\n", i); i++; while int i = 0; i while (i < 100) { printf("i = %3d\n", i); i++; while int i =

More information

新版明解C言語 実践編

新版明解C言語 実践編 2 List - "max.h" a, b max List - max "max.h" #define max(a, b) ((a) > (b)? (a) : (b)) max List -2 List -2 max #include "max.h" int x, y; printf("x"); printf("y"); scanf("%d", &x); scanf("%d", &y); printf("max(x,

More information

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

新・明解C言語 ポインタ完全攻略 2 1-1 1-1 /* 1-1 */ 1 int n = 100; int *p = &n; printf(" n %d\n", n); /* n int */ printf("*&n %d\n", *&n); /* *&n int */ printf(" p %p\n", p); /* p int * */ printf("&*p %p\n", &*p); /* &*p int * */ printf("sizeof(n)

More information

ex12.dvi

ex12.dvi 1 0. C, char., char, 0,. C, ("),., char str[]="abc" ; str abc.,, str 4. str 3. char str[10]="abc" ;, str 10, str 3., char s[]="abc", t[10] ;, t = s. ASCII, 0x00 0x7F, char., "abc" 3, 1. 1 8 256, 2., 2

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

解きながら学ぶC++入門編

解きながら学ぶC++入門編 !... 38!=... 35 "... 112 " "... 311 " "... 4, 264 #... 371 #define... 126, 371 #endif... 369 #if... 369 #ifndef... 369 #include... 3, 311 #undef... 371 %... 17, 18 %=... 85 &... 222 &... 203 &&... 40 &=...

More information

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

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( ) 2008 3 10 1 mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( ) stream FILE ( man ) 40 ( ) %./a.out String : test

More information

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

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n 2008 3 10 1 mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( ) stream FILE ( man ) 40 ( ) %./a.out String : test

More information

double float

double float 2015 3 13 1 2 2 3 2.1.......................... 3 2.2............................. 3 3 4 3.1............................... 4 3.2 double float......................... 5 3.3 main.......................

More information

(2 Linux Mozilla [ ] [ ] [ ] [ ] URL 2 qkc, nkc ~/.cshrc (emacs 2 set path=($path /usr/meiji/pub/linux/bin tcsh b

(2 Linux Mozilla [ ] [ ] [ ] [ ] URL   2 qkc, nkc ~/.cshrc (emacs 2 set path=($path /usr/meiji/pub/linux/bin tcsh b II 5 (1 2005 5 26 http://www.math.meiji.ac.jp/~mk/syori2-2005/ UNIX (Linux Linux 1 : 2005 http://www.math.meiji.ac.jp/~mk/syori2-2005/jouhousyori2-2005-00/node2. html ( (Linux 1 2 ( ( http://www.meiji.ac.jp/mind/tool/internet-license/

More information

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

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B 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

More information

‚æ4›ñ

‚æ4›ñ ( ) ( ) ( ) A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 (OUS) 9 26 1 / 28 ( ) ( ) ( ) A B C D Z a b c d z 0 1 2 9 (OUS) 9

More information

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

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 18 C ( ) 1 1 1.1 hello world.c 5 printf("hello World\n"); 6 } [ ] [ ] #include % cc hello_world.c %./a.out Hello World [a.out ] % cc hello_world.c -o hello_world [ ( ) ] (K&R 4.1.1) #include

More information

PowerPoint プレゼンテーション

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

More information

joho07-1.ppt

joho07-1.ppt 0xbffffc5c 0xbffffc60 xxxxxxxx xxxxxxxx 00001010 00000000 00000000 00000000 01100011 00000000 00000000 00000000 xxxxxxxx x y 2 func1 func2 double func1(double y) { y = y + 5.0; return y; } double func2(double*

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

解きながら学ぶC言語

解きながら学ぶC言語 printf 2-5 37 52 537 52 printf("%d\n", 5 + 37); 5370 source program source file.c ex00.c 0 comment %d d 0 decimal -2 -p.6 3-2 5 37 5 37-22 537 537-22 printf("537%d\n", 5-37); function function call ( )argument,

More information

I117 7 School of Information Science, Japan Advanced Institute of Science and Technology

I117 7 School of Information Science, Japan Advanced Institute of Science and Technology I117 7 School of Information Science, Japan Advanced Institute of Science and Technology time time t long typedef long time_t; 1970/01/01 0:00:00 time t = time(null); Japan Advanced Institute of Science

More information

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

:30 12:00 I. I VI II. III. IV. a d V. VI 2018 2018 08 02 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF N N y N x N xy yx : yxxyxy N N x, y N (parse tree) (1) yxyyx (2) xyxyxy (3) yxxyxyy (4) yxxxyxxy N y N x N yx

More information

+ +

+ + + + 2 1 1 1.1................................ 1 1.2........................... 2 1.3............................. 2 1.4 ( ).................. 2 1.5........................ 3 1.6...................... 3

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

tuat1.dvi

tuat1.dvi ( 1 ) http://ist.ksc.kwansei.ac.jp/ tutimura/ 2012 6 23 ( 1 ) 1 / 58 C ( 1 ) 2 / 58 2008 9 2002 2005 T E X ptetex3, ptexlive pt E X UTF-8 xdvi-jp 3 ( 1 ) 3 / 58 ( 1 ) 4 / 58 C,... ( 1 ) 5 / 58 6/23( )

More information

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

Microsoft Word - C.....u.K...doc C uwêííôöðöõ Ð C ÔÖÐÖÕ ÐÊÉÌÊ C ÔÖÐÖÕÊ C ÔÖÐÖÕÊ Ç Ê Æ ~ if eíè ~ for ÒÑÒ ÌÆÊÉÉÊ ~ switch ÉeÍÈ ~ while ÒÑÒ ÊÍÍÔÖÐÖÕÊ ~ 1 C ÔÖÐÖÕ ÐÊÉÌÊ uê~ ÏÒÏÑ Ð ÓÏÖ CUI Ô ÑÊ ÏÒÏÑ ÔÖÐÖÕÎ d ÈÍÉÇÊ ÆÒ Ö ÒÐÑÒ ÊÔÎÏÖÎ d ÉÇÍÊ

More information

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

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

More information

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

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 II 8 2003 11 12 1 6 ( ) 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 Daisuke 8 =>. 73 Daisuke 35 Hiroshi 64 Ichiro 87 Junko

More information

prog-text.dvi

prog-text.dvi (C ) 2008 1 2008.8.7 8 1 E mail : sakkun@yokohama-cu.ac.jp 3 I 13 1 17 1.1.......................... 17 1.1.1.......................... 17 1.1.2 OS................ 17 1.2..............................

More information

10

10 2: http://www7.bpe.es.osaka-u.ac.jp/~kota/classes/jse.html kota@fbs.osaka-u.ac.jp 10 : 0 1 2 n 2 n 0 1 1 0 1 0 0 1 (2) = 105 1 = 8 1 2 8 = 256 0 9 105 i 106 j 256 2 1 #include int main(void)

More information

untitled

untitled II yacc 005 : 1, 1 1 1 %{ int lineno=0; 3 int wordno=0; 4 int charno=0; 5 6 %} 7 8 %% 9 [ \t]+ { charno+=strlen(yytext); } 10 "\n" { lineno++; charno++; } 11 [^ \t\n]+ { wordno++; charno+=strlen(yytext);}

More information

ex14.dvi

ex14.dvi 1,, 0, b (b b 2 b ) n k n = n j b j, (0 n j b 1), n =(n k n k 1...n 1 n 0 ) b, n j j j +1, 0,...,b 1 (digit). b b, n b 1 ñ, ñ = k (b 1 n j )b j b N, n b n, n = b N n, n =ñ+1 b N, n m n + m (mod b 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

数値計算

数値計算 プログラム作成から実行まで 数値計算 垣谷公徳 17 号館 3 階電子メール : kimi@ee.ous.ac.jp Source program hello.c printf("hello\n"); コンパイラ Library libc.a 0011_printf000101001 1101_getc00011100011 1011_scanf1110010100 コンパイル Object module

More information

超初心者用

超初心者用 3 1999 10 13 1. 2. hello.c printf( Hello, world! n ); cc hello.c a.out./a.out Hello, world printf( Hello, world! n ); 2 Hello, world printf n printf 3. ( ) int num; num = 100; num 100 100 num int num num

More information

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

:30 12:00 I. I VI II. III. IV. a d V. VI 2017 2017 08 03 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF X [ S ] a S S ; X X X, S [, a, ], ; BNF X (parse tree) (1) [a;a] (2) [[a]] (3) [a;[a]] (4) [[a];a] : [a] X 2 222222

More information

ohp03.dvi

ohp03.dvi 19 3 ( ) 2019.4.20 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void int main(int argc, char *argv[]) {... 2 (2) argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0

More information

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

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU 1. 1.1. 1.2. 1 PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU 2. 2.1. 2 1 2 C a b N: PC BC c 3C ac b 3 4 a F7 b Y c 6 5 a ctrl+f5) 4 2.2. main 2.3. main 2.4. 3 4 5 6 7 printf printf

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

新・明解C言語 実践編

新・明解C言語 実践編 第 1 章 見 21 1-1 見えないエラー 見 List 1-1 "max2x1.h" a, b max2 List 1-1 chap01/max2x1.h max2 "max2x1.h" #define max2(a, b) ((a) > (b)? (a) : (b)) max2 List 1-2 List 1-2 chap01/max2x1test.c max2 #include

More information

r08.dvi

r08.dvi 19 8 ( ) 019.4.0 1 1.1 (linked list) ( ) next ( 1) (head) (tail) ( ) top head tail head data next 1: NULL nil ( ) NULL ( NULL ) ( 1 ) (double linked list ) ( ) 1 next 1 prev 1 head cur tail head cur prev

More information

ohp08.dvi

ohp08.dvi 19 8 ( ) 2019.4.20 1 (linked list) ( ) next ( 1) (head) (tail) ( ) top head tail head data next 1: 2 (2) NULL nil ( ) NULL ( NULL ) ( 1 ) (double linked list ) ( 2) 3 (3) head cur tail head cur prev data

More information

C V C 6 1 6.1.............................. 1 6.......................... 3 6.3..................... 5 6.4 NULL............................. 8 6.5......................... 9 6.6..............................

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

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

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 C/C++ 2007 6 18 1 C STL(1) 2 1.1............................................... 2 1.2 stdio................................................ 3 1.3.......................................... 10 2 11 2.1 sizeof......................................

More information

r07.dvi

r07.dvi 19 7 ( ) 2019.4.20 1 1.1 (data structure ( (dynamic data structure 1 malloc C free C (garbage collection GC C GC(conservative GC 2 1.2 data next p 3 5 7 9 p 3 5 7 9 p 3 5 7 9 1 1: (single linked list 1

More information

r03.dvi

r03.dvi 19 ( ) 019.4.0 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void... argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0 a a \0 b b b \0 c c c \0 1: // argdemo1.c ---

More information

ohp07.dvi

ohp07.dvi 19 7 ( ) 2019.4.20 1 (data structure) ( ) (dynamic data structure) 1 malloc C free 1 (static data structure) 2 (2) C (garbage collection GC) C GC(conservative GC) 2 2 conservative GC 3 data next p 3 5

More information

Fortran90/95 [9]! (1 ) " " 5 "Hello!"! 3. (line) Fortran Fortran 1 2 * (1 ) 132 ( ) * 2 ( Fortran ) Fortran ,6 (continuation line) 1

Fortran90/95 [9]! (1 )   5 Hello!! 3. (line) Fortran Fortran 1 2 * (1 ) 132 ( ) * 2 ( Fortran ) Fortran ,6 (continuation line) 1 Fortran90/95 2.1 Fortran 2-1 Hello! 1 program example2_01! end program 2! first test program ( ) 3 implicit none! 4 5 write(*,*) "Hello!"! write Hello! 6 7 stop! 8 end program example2_01 1 program 1!

More information

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

/* 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 */ } C 2: A Pedestrian Approach to the C Programming Language 2 2-1 2.1........................... 2-1 2.1.1.............................. 2-1 2.1.2......... 2-4 2.1.3..................................... 2-6

More information

kiso2-06.key

kiso2-06.key 座席指定があります Linux を起動して下さい 第6回 計算機基礎実習II 計算機基礎実習II 2018 のウェブページか ら 以下の課題に自力で取り組んで下さい 第5回の復習課題(rev05) 第6回の基本課題(base06) 第5回課題の回答例 ex05-2.c 1. キーボードから整数値 a を入力すると a*a*a の値を出力することを繰り返すプログラムを作成しなさい 2. ただし 入力された

More information

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

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include 1 1.1 C 2 1 double a[ ][ ]; 1 3x3 0 1 3x3 ( ) 0.240 0.143 0.339 0.191 0.341 0.477 0.412 0.003 0.921 1.2 malloc() malloc 2 #include #include #include enum LENGTH = 10 ; int

More information

新版明解C言語入門編

新版明解C言語入門編 175cm 60kg ( ) 175cm 175.3cm 175.869758 cm 175cm 60kg p.177 18-1 vx - vy vx vy List -1 List -1 int vx, vy; puts(""); printf(" vx "); scanf("%d", &vx); printf(" vy "); scanf("%d", &vy); printf("vx + vy

More information

2008 IIA (program) pro(before)+gram(write) (artificial language) (programming languege) (programming) (machine language) (assembly language) ( )

2008 IIA (program) pro(before)+gram(write) (artificial language) (programming languege) (programming) (machine language) (assembly language) ( ) 2008 IIA 1 1.1 (program) pro(before)+gram(write) (artificial language) (programming languege) (programming) (machine language) (assembly language) () (high-level language) 3 (machine language) (CPU) 0

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

スライド タイトルなし

スライド タイトルなし ファイル入出力 (2) これまでのおさらい ( 入出力 ) これまでの入出力は 入力 scanf 出力 printf キーボードと画面 ( 端末 ) scanf/printf は 書式つき入出力 フォーマットを指定する 標準入出力を対象とする 何もしなければ 標準入出力は キーボードと画面 ストリームという考え方 ストリーム (stream) = データの列 キーボードから打つ文字列 画面に出力される文字列

More information

数値計算

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

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

C

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

More information

PowerPoint Presentation

PowerPoint Presentation p.130 p.198 p.208 2 double weight[num]; double min, max; min = max = weight[0]; for( i= 1; i i < NUM; i++ ) ) if if ( weight[i] > max ) max = weight[i]: if if ( weight[i] < min ) min = weight[i]: weight

More information

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() 2 double *a[ ]; double 1 malloc() dou 1 1.1 C 2 1 double a[ ][ ]; 1 3x3 0 1 3x3 ( ) 0.240 0.143 0.339 0.191 0.341 0.477 0.412 0.003 0.921 1.2 malloc() 2 double *a[ ]; double 1 malloc() double 1 malloc() free() 3 #include #include

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

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

ARM gcc Kunihiko IMAI 2009 1 11 ARM gcc 1 2 2 2 3 3 4 3 4.1................................. 3 4.2............................................ 4 4.3........................................

More information

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

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

More information

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-

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- 1 C IIA 1 C IIA IIA 1.1 Mac OS X 1.1.1 Mac OS X Unicode(UTF-8) UTF-8 Jedit X( ) Emacs( ) Emacs Emacs Emacs [Finder] [] Emacs dock Jedit X C 1. Jedit X Dock drag & drop Jedit X [Finder] [] Jedit X Folder

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

untitled

untitled C -1 - -2 - concept lecture keywords FILE, fopen, fclose, fscanf, fprintf, EOF, r w a, typedef gifts.dat Yt JZK-3 Jizake tsumeawase 45 BSP-15 Body soap set 3 BT-2 Bath towel set 25 TEA-2 Koutya

More information

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

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç C (3) if else switch AND && OR (NOT)! 1 BMI BMI BMI = 10 4 [kg]) ( [cm]) 2 bmi1.c Input your height[cm]: 173.2 Enter Input your weight[kg]: 60.3 Enter Your BMI is 20.1. 10 4 = 10000.0 1 BMI BMI BMI = 10

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

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

program.dvi

program.dvi 2001.06.19 1 programming semi ver.1.0 2001.06.19 1 GA SA 2 A 2.1 valuename = value value name = valuename # ; Fig. 1 #-----GA parameter popsize = 200 mutation rate = 0.01 crossover rate = 1.0 generation

More information

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

Minimum C Minimum C Minimum C BNF T okenseq W hite Any D 6 2019 5 14 6.1 Minimum C....................... 6 1 6.2....................................... 6 7 6.1 Minimum C Minimum C BNF T okenseq W hite Any Digit ::= 0 1 2... 9. Number ::= Digit Digit. Alphabet

More information

BW BW

BW BW Induced Sorting BW 11T2042B 2015 3 23 1 1 1.1................................ 1 1.2................................... 1 2 BW 1 2.1..................................... 2 2.2 BW.................................

More information

9 ライブラリ関数 ( 教科書 P.84) C 言語には使用頻度が高そうな機能は関数として用意されており, それらは幾つかのライブラリに分類されている. それらの総称を C 言語標準ライブラリと呼ぶ. 次を参照のこと.

9 ライブラリ関数 ( 教科書 P.84) C 言語には使用頻度が高そうな機能は関数として用意されており, それらは幾つかのライブラリに分類されている. それらの総称を C 言語標準ライブラリと呼ぶ. 次を参照のこと. 9 ライブラリ関数 ( 教科書 P.84) C 言語には使用頻度が高そうな機能は関数として用意されており, それらは幾つかのライブラリに分類されている. それらの総称を C 言語標準ライブラリと呼ぶ. 次を参照のこと. http://ja.wikipedia.org/wiki/%e6%a8%99%e6%ba%96c%e3%83%a9%e3%82%a4%e3%83%9 6%E3%83%A9%E3%83%AA

More information

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

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 I 4 003 4 30 1 ASCII ( ) 0 17 0 NUL 16 DLE SP 0 @ P 3 48 64 80 96 11 p 1 SOH 17 DC1! 1 A Q a 33 49 65 81 97 113 q STX 18 DC " B R b 34 50 66 8 98 114 r 3 ETX 19 DC3 # 3 C S c 35 51 67 83 99 115 s 4 EOT

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

I J

I J I 065763J 8 7 7 31 jikken/ +----- accumulation_demupa.c +----- accumulation_rain.c +----- frequency_demupa.c +----- frequency_rain.c +----- go.sh +----- graph_maker.sh +----- mesure-ryudai/ 2007/4/1 2007/6/30

More information

Informatics 2010.key

Informatics 2010.key http://math.sci.hiroshima-u.ac.jp/ ~ryo/lectures/informatics2010/ 1 2 C ATM etc. etc. (Personal Computer) 3 4 Input Output Device Central Processing Unit I/O CPU Memory 5 6 (CPU),,... etc. C, Java, Fortran...

More information

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

Microsoft Word - Cプログラミング演習(8) 第 8 回 (6/11) プログラミングスタイルなど [1] 名前のつけかた グローバル変数にはわかりやすい名前を, ローカル変数には短い名前を 関連性のあるものには関連性のある名前をつけて, 統一しよう 関数には能動的な名前を 名前は的確に 例題 1 次のコードの名前と値の選び方についてコメントせよ? #define TRUE 0? #define FALSE 1?? if ((ch = getchar())

More information

計算機プログラミング

計算機プログラミング プログラミング言語 C 第 8 講 システム標準関数 ( 入出力関数 ) システム標準関数 システムに備え付けの関数 例 ) printf( ); scanf( ); 標準出力関数 標準入力関数 A. 入出力用の関数 高水準入出力関数 高水準言語 (OS に依存しない ) 低水準入出力関数 機械語レベル (OS に依存 ) B. それ以外の関数 引数と関数の型 ( 戻り値 ) に注目しましょう 例

More information

Informatics 2014

Informatics 2014 C 計算機の歴史 手回し計算機 新旧のソロバン バベッジの階差機関 スパコン ENIAC (1946) パソコン 大型汎用計算機 電卓 現在のコンピュータ Input Output Device Central Processing Unit I/O CPU Memory OS (Operating System) OS Windows 78, Vista, XP Windows Mac OS X

More information

TEX American Mathematical Society PostScript Adobe Systems Incorporated

TEX American Mathematical Society PostScript Adobe Systems Incorporated P A D manual ( pad2ps 3.1j ) (seiichi@muraoka.info.waseda.ac.jp) 1996 11 2 TEX American Mathematical Society PostScript Adobe Systems Incorporated pad2ps PAD PAD (Problem Analysis Diagram) C 1 2 PAD PAD

More information

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

Microsoft PowerPoint - CproNt11.ppt [互換モード] 第 11 章入出力関数とライブラリ関数 CPro:11-01 概要 getchar putchar gets puts scanf printf strcat strcmp strcpy strlen atoi atof sprint sscanf 11.1 コンソール入出力関数 11-02 入力 出力 getchar putchar 一文字 gets puts 文字列 ( 一行 ) scanf printf

More information

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

2 P.S.P.T. P.S.P.T. wiki  26 P.S.P.T. C 2011 4 10 2 P.S.P.T. P.S.P.T. wiki p.s.p.t.since1982@gmail.com http://www23.atwiki.jp/pspt 26 3 2 1 C 8 1.1 C................................................ 8 1.1.1...........................................

More information

tuat2.dvi

tuat2.dvi ( 2 ) http://ist.ksc.kwansei.ac.jp/ tutimura/ 2012 7 7 ( 2 ) 1 / 54 (1) (2) (?) (1) (2) 2 ( 2 ) 2 / 54 1. 30 2. 2012 6 30 25 OS ( 2 ) 3 / 54 10 20 1993 1996 2000 2003 = 30 ( 2 ) 4 / 54 1 2 2 ( 2 ) 5 /

More information

C B

C B C 095707B 2010 6 8 1 LEVE1 2 1.1 LEVEL 1.1................................................ 2 1.1.1 1................................................ 2 1.1.2 1.2..............................................

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

lexex.dvi

lexex.dvi (2018, c ) http://istksckwanseiacjp/ ishiura/cpl/ 4 41 1 mini-c lexc,, 2 testlexc, lexc mini-c 1 ( ) mini-c ( ) (int, char, if, else, while, return 6 ) ( ) (+, -, *, /, %, &, =, ==,!=, >, >=,

More information

A 30 A A ( ) 2 C C (, machine language) C (C compiler) ( ) Mac Apple Xcode Clan

A 30 A A ( ) 2 C C (, machine language) C (C compiler) ( ) Mac Apple Xcode Clan C 2017 9 29, 30 5 13 http://nalab.mind.meiji.ac.jp/~mk/labo/text/ 1 2 2 C 2 3 4 3.1 C................................... 4 3.2 Hello world........................................ 5 3.3 5...............................

More information

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

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 II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C 1 6 9 1 main main 1 NULL NULL 1 15 23 25 48 26 30 32 36 38 43 45 47 50 52 for 2 (a) 2 2 1 Yacc 2 (b) 2 3 yytext tmp2 ("") tmp2->next->word tmp2 yytext tmp2->next->word

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

Informatics 2015

Informatics 2015 C 計算機の歴史 新旧のソロバン バベッジの階差機関 19C前半 手回し計算機 19C後半 20C後半 スパコン 1960年代 ENIAC (1946) 大型汎用計算機 1950年代 1980年代 電卓 1964 パソコン 1970年代 現在のコンピュータ Input Output Device Central Processing Unit I/O CPU Memory OS (Operating

More information

Excel ではじめる数値解析 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 初版 1 刷発行時のものです.

Excel ではじめる数値解析 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます.   このサンプルページの内容は, 初版 1 刷発行時のものです. Excel ではじめる数値解析 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. http://www.morikita.co.jp/books/mid/009631 このサンプルページの内容は, 初版 1 刷発行時のものです. Excel URL http://www.morikita.co.jp/books/mid/009631 i Microsoft Windows

More information

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

Microsoft PowerPoint - CproNt02.ppt [互換モード] 第 2 章 C プログラムの書き方 CPro:02-01 概要 C プログラムの構成要素は関数 ( プログラム = 関数の集まり ) 関数は, ヘッダと本体からなる 使用する関数は, プログラムの先頭 ( 厳密には, 使用場所より前 ) で型宣言 ( プロトタイプ宣言 ) する 関数は仮引数を用いることができる ( なくてもよい ) 関数には戻り値がある ( なくてもよい void 型 ) コメント

More information

ex01.dvi

ex01.dvi ,. 0. 0.0. C () /******************************* * $Id: ex_0_0.c,v.2 2006-04-0 3:37:00+09 naito Exp $ * * 0. 0.0 *******************************/ #include int main(int argc, char **argv) double

More information

9 8 7 (x-1.0)*(x-1.0) *(x-1.0) (a) f(a) (b) f(a) Figure 1: f(a) a =1.0 (1) a 1.0 f(1.0)

9 8 7 (x-1.0)*(x-1.0) *(x-1.0) (a) f(a) (b) f(a) Figure 1: f(a) a =1.0 (1) a 1.0 f(1.0) E-mail: takio-kurita@aist.go.jp 1 ( ) CPU ( ) 2 1. a f(a) =(a 1.0) 2 (1) a ( ) 1(a) f(a) a (1) a f(a) a =2(a 1.0) (2) 2 0 a f(a) a =2(a 1.0) = 0 (3) 1 9 8 7 (x-1.0)*(x-1.0) 6 4 2.0*(x-1.0) 6 2 5 4 0 3-2

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

num2.dvi

num2.dvi kanenko@mbk.nifty.com http://kanenko.a.la9.jp/ 16 32...... h 0 h = ε () 0 ( ) 0 1 IEEE754 (ieee754.c Kerosoft Ltd.!) 1 2 : OS! : WindowsXP ( ) : X Window xcalc.. (,.) C double 10,??? 3 :, ( ) : BASIC,

More information

i

i i 3 4 4 7 5 6 3 ( ).. () 3 () (3) (4) /. 3. 4/3 7. /e 8. a > a, a = /, > a >. () a >, a =, > a > () a > b, a = b, a < b. c c n a n + b n + c n 3c n..... () /3 () + (3) / (4) /4 (5) m > n, a b >, m > n,

More information