http://cafedaumnet/pway
Chapter 1
Chapter 2 21 printf("this is my first program\n"); printf("\n"); printf("-------------------------\n"); printf("this is my second program\n"); printf("-------------------------\n"); 22 int a, b, c; a = 1; b = 2; c = a + b; printf("a=%d b=%d c=%d\n", a, b, c); 23 int a, b, c; printf("please enter two numbers:");
scanf("%d %d", &a, &b); c = a + b; printf("\na=%d b=%d c=%d", a, b, c); 24 int i, n; printf("\nplease enter number:"); scanf("%d", &n); printf("\n"); printf("yes "); printf("\n print %d many yes",n); int i, n; printf("\nplease enter number:"); scanf("%d", &n); printf("\n"); printf("%d", i); printf("\n print the numbers from 0 to %d", n-1); 241 for 1 for(i=0;i<10;i++) printf("yes "); for(i=0;i<100;i++) printf("happy "); for(i=0;i<1000;i++) printf("laugh "); 242 for 2
printf("yes "); 0 i=0; 1 i<n; 0<3, 2 printf("yes "); 3 i++ i 1 i=1 4 i<n; 1<3, 5 printf("yes "); 6 i++ i 1 i=2 7 i<n; 2<3, 8 printf("yes "); 9 i++ i 1 i=3 10 i<n; 3<3, 11 for 243 for 3 printf("yes "); for( ; ; ) 244 for 4 printf("%d", i); 0 i=0; 1 i<n; 0<3, 2 printf("%d", i); 0 3 i++ i 1 i=1 4 i<n; 1<3, 5 printf("%d", i); 1 6 i++ i 1 i=2 7 i<n; 2<3, 8 printf("%d", i); 2 9 i++ i 1 i=3
10 i<n; 3<3, 11 for 25 int i, n; printf("\nplease enter number:"); scanf("%d", &n); printf("%d", i+1); int i, j, n; printf("\nplease enter number:"); scanf("%d", &n); for(j=0;j<n;j++) printf("%4d", j+1); printf("\n"); 251 for 5 1 2 3 4 int i, j, n; 5 6 printf("\nplease enter number:"); 7 scanf("%d", &n); 9 10 11 12 for(j=0;j<n;j++) 13 printf("%4d", j+1); 14 printf("\n"); 15 16 17 : for?
: 10 11 15 : 5? : C ( ) : for? : for for :? : 252 for 6 1 2 3 4 int i, j, n; 5 6 printf("\nplease enter number:"); 7 scanf("%d", &n); 9 10 11 12 for(j=0;j<n;j++) 13 printf("%4d", j+1); 14 printf("\n"); 15 16 17 10 for : i=0 i 0 : i<3 : 11-15 12 for : j=0 j 0 : j<3 : printf("%4d", j+1); 1 : j++ j 1 : j<3 : printf("%4d", j+1); 2 : j++ j 2 : j<3 : printf("%4d", j+1); 3 : j++ j 3 j<3 for (12 ) 14 printf("\n"); (11-15 ) : i++ i 1 : i<3 : 11-15 12 for
: j=0 j 0 : j<3 : printf("%4d", j+1); 1 : j++ j 1 : j<3 : printf("%4d", j+1); 2 : j++ j 2 : j<3 : printf("%4d", j+1); 3 : j++ j 3 j<3 for (12 ) 14 printf("\n"); (11-15 ) : i++ i 2 : i<3 : 11-15 12 for : j=0 j 0 : j<3 : printf("%4d", j+1); 1 : j++ j 1 : j<3 : printf("%4d", j+1); 2 : j++ j 2 : j<3 : printf("%4d", j+1); 3 : j++ j 3 j<3 for (12 ) 14 printf("\n"); (11-15 ) : i++ i 3 : i<3 for (10 ) 1 2 3 1 2 3 1 2 3 26 int i, j, n; printf("\nplease enter number:"); scanf("%d", &n); for(j=0;j<n;j++) printf("%4d", j+1); printf("\n");
27 int i, j, k, n; printf("\nplease enter number:"); scanf("%d", &n); k = 1; for(j=0;j<n;j++) printf("%4d", k++); printf("\n"); 28 int i, j, n; printf("\nplease enter number:"); scanf("%d", &n); for(j=0;j<i+1;j++) printf("%4d", j+1); printf("\n"); int i, j, n; printf("\nplease enter number:"); scanf("%d", &n); for(j=0;j<n-i;j++) printf("%4d", j+1); printf("\n");
281 for 7 1 2 3 4 int i, j, k, n; 5 6 printf("\nplease enter number:"); 7 scanf("%d", &n); 9 10 k=1; 11 12 13 for(j=0;j<n;j++) 14 printf("%4d", k++); 15 printf("\n"); 16 17 18 10 k=1; k 1 11 for : i=0 i 0 : i<3 : 12-16 13 for : j=0 j 0 : j<3 : printf("%4d", k++); 1 k 2 : j++ j 1 : j<3 : printf("%4d", k++); 2 k 3 : j++ j 2 : j<3 : printf("%4d", k++); 3 k 4 : j++ j 3 j<3 for (13 ) 15 printf("\n"); (12-16 ) : i++ i 1 : i<3 : 12-16 13 for : j=0 j 0 : j<3 : printf("%4d", k++); 4 k 5 : j++ j 1 : j<3 : printf("%4d", k++); 5 k 6 : j++ j 2 : j<3 : printf("%4d", k++); 6 k 7 : j++ j 3 j<3 for (13 )
15 printf("\n"); (12-16 ) : i++ i 2 : i<3 : 12-16 13 for : j=0 j 0 : j<3 : printf("%4d", k++); 7 k 8 : j++ j 1 : j<3 : printf("%4d", k++); 8 k 9 : j++ j 2 : j<3 : printf("%4d", k++); 9 k 10 : j++ j 3 j<3 for (13 ) 15 printf("\n"); (12-16 ) : i++ i 3 : i<3 for (11 ) 1 2 3 4 5 6 7 8 9 282 for 8 1 2 3 4 int i, j, n; 5 6 printf("\nplease enter number:"); 7 scanf("%d", &n); 8 9 10 11 for(j=0;j<i+1;j++) 12 printf("%4d", j+1); 13 printf("\n"); 14 15 16
1 1 2 1 2 3 283 for 9 1 2 3 4 int i, j, n; 5 6 printf("\nplease enter number:"); 7 scanf("%d", &n); 8 9 10 11 for(j=0;j<n-i;j++) 12 printf("%4d", j+1); 13 printf("\n"); 14 15 16 1 2 3 1 2 1
Chapter 3
Chapter 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 21 22 23 24 25 16 17 18 19 20 11 12 13 14 15 6 7 8 9 10 1 2 3 4 5 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 5 6 7 8 9 1 2 3 4 5 2 3 4 5 1 3 4 5 1 2 4 5 1 2 3 5 1 2 3 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Chapter 5 ***** ***** ***** ***** ***** * ** *** **** ***** * ** *** **** ***** * *** ***** ******* ********* * *** ***** ******* ********* ******* ***** *** *
* * *** *** ***** ***** ******* ******* ****************** ******* ******* ***** ***** *** *** * * [ n, 2-8 ] * ********* * *** *********** *** ***** ************* ***** ******* *************** ******* *********************************** [ 2*n ] * *** ***** ******* ********* * *********** * *** ************* *** ***** *************** ***** ******* ***************** ******* ************************************* $$$$$$$ $*****$ $*****$ $*****$ $*****$ $*****$ $$$$$$$ [ n+2 + n+1 = 2*n + 3 ] [ *2 ] [ *1 ] * ** *@* *@@* *@@@* *@@@@* *@@@@@* *@@@@* *@@@* *@@* *@* ** *
int i, j, n; printf("\nplease enter number:"); scanf("%d", &n); for(j=0;j<n;j++) printf("*"); printf("\n");
Chapter 6 61 int a[30][30]; int i, j, k, n; printf("\nplease enter number:"); scanf("%d", &n); k=0; for(j=0;j<n;j++) a[i][j] = k++; for(j=0;j<n;j++) printf("%4d", a[i][j]); printf("\n");
611 1 1 2 3 ( ) 4 5 a[ 0][ 0], a[ 0][ 1], a[ 0][ 2], a[ 0][ 3],,,, a[ 0][28], a[ 0][29], a[ 1][ 0], a[ 1][ 1], a[ 1][ 2], a[ 1][ 3],,,, a[ 1][28], a[ 1][29], a[ 2][ 0], a[ 2][ 1], a[ 2][ 2], a[ 2][ 3],,,, a[ 2][28], a[ 2][29], a[29][ 0], a[29][ 1], a[29][ 2], a[29][ 3],,,, a[29][28], a[29][29] 612 2 1 2 3 4 int a[30][30]; 5 int i, j, k, n; 6 7 printf("\nplease enter number:"); 8 scanf("%d", &n); 9 10 k=0; 11 12 for(j=0;j<n;j++) 13 a[i][j] = k++; 14 15 16 17 for(j=0;j<n;j++) 18 printf("%4d", a[i][j]); 19 printf("\n"); 20
21 22 62 int a[30][30]; int i, j, k, n; printf("\nplease enter number:"); scanf("%d", &n); for(j=0;j<n;j++) a[i][j]=j+1; // [A] for(j=0;j<n;j++) printf("%4d", a[i][j]); printf("\n"); : a[i][j]=i+1; : a[i][j]=i+j+1; : a[i][j]=i-j; : a[i][j]=j-i; : a[i][j]=(i+1)*(j+1); 63 int a[30][30]=0,; int i, j, k, n; printf("\nplease enter number:"); scanf("%d", &n); a[i][i]=i+1; // [A] for(j=0;j<n;j++)
printf("%4d", a[i][j]); printf("\n"); : a[i][i]=n-i; : a[0][i]=i+1; : a[n-1][i]=i+1; : a[i][0]=i+i; : a[i][n-1]=i+1; : a[i][n-i-1]=i+1; 64 int a[30][30]=0,; int i, j, k, n; printf("\nplease enter number:"); scanf("%d", &n); k=0; a[i][i]=k++; // [A] for(j=0;j<n;j++) printf("%4d", a[i][j]); printf("\n"); : a[0][i]=k++; : a[n-1][i]=k++; : a[i][0]=k++; : a[i][n-1]=k++; : a[i][n-i-1]=k++; : a[n-i-1][i]=k++; 65 int a[30][30]=0,; int i, j, k, n; printf("\nplease enter number:"); scanf("%d", &n); k=0;
for(j=0;j<n;j++) a[i][j]=k++; // [A] for(j=0;j<n;j++) printf("%4d", a[i][j]); printf("\n"); : a[j][i]=k++; : a[i][n-j-1]=k++; : a[n-i-1][j]=k++; : a[n-i-1][n-j-1]=k++; : a[j][n-i-1]=k++; : a[n-j-1][i]=k++; 66 int i, n; printf("\nplease enter number:"); scanf("%d", &n); if((i%2)==0) printf("\ni=%d is even number", i); else printf("\ni=%d is odd number", i); // // 67 int a[30][30]; int i, j, n; printf("\nplease enter number:"); scanf("%d", &n); for(j=0;j<n;j++) if(i==j) a[i][j]=9; else a[i][j]=1;
for(j=0;j<n;j++) printf("%4d", a[i][j]); printf("\n"); 9 1 1 1 1 1 9 1 1 1 1 1 9 1 1 1 1 1 9 1 1 1 1 1 9 int a[30][30]; int i, j, n; printf("\nplease enter number:"); scanf("%d", &n); for(j=0;j<n;j++) if(i>j) a[i][j]=9; else a[i][j]=1; for(j=0;j<n;j++) printf("%4d", a[i][j]); printf("\n"); 1 1 1 1 1 9 1 1 1 1 9 9 1 1 1 9 9 9 1 1 9 9 9 9 1 if((i%2)==0) % i%2 i 2 i 0, 1 if((i%2)==0) i
Chapter 7 (2 ) number = 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 number = 5 1 6 11 16 21 2 7 12 17 22 3 8 13 18 23 4 9 14 19 24 5 10 15 20 25 number = 5 21 22 23 24 25 16 17 18 19 20 11 12 13 14 15 6 7 8 9 10 1 2 3 4 5 number = 5 1 2 3 4 5 10 9 8 7 6 11 12 13 14 15 20 19 18 17 16 21 22 23 24 25 number = 7 9 9 9 9 9 9 9 9 9 0 0 0 9 9 9 0 9 0 9 0 9 9 0 0 9 0 0 9 9 0 9 0 9 0 9 9 9 0 0 0 9 9 9 9 9 9 9 9 9
number = 5 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 number = 6 1 1 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1 1 number = 6 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 number = 5 1 2 3 4 5 16 0 0 0 6 15 0 0 0 7 14 0 0 0 8 13 12 11 10 9 number = 5 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 number = 5 3 3 3 3 3 3 2 2 2 3 3 2 1 2 3 3 2 2 2 3 3 3 3 3 3
number = 5 1 3 6 10 15 2 5 9 14 19 4 8 13 18 22 7 12 17 21 24 11 16 20 23 25 number = 3 : 8 1 6 3 5 7 4 9 2 number = 5 : 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 1 (3X3, 5x5) 2 3 4 5 3x3 1 a[0][1] 2 a[-1][2] -1 a[2][2] 3 a[1][3] 3 a[1][0] 4 a[0][1] a[2][0] 5 a[1][1] 6 a[0][2] 7 a[-1][3] -1, 3 a[2][0] a[0][2] a[1][2] 8 a[0][3] 3 a[0][0]
9 a[-1][1] a[2][1]
Chapter 8 - int i, n; printf("\nplease enter number:"); scanf("%d", &n); i=0; while(i<n) printf("\ni=%4d", i); i++; printf("\ni=%4d", i); while( ) ; int a[100]=1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ; int i, n; printf("\nprint the contents of array a[]"); i=0; while(a[i]>0) printf("%4d", a[i]); i++; int a[100]=11, 12, 13, 14, 15, 6, 7, 8, 9, 10, ; int i, n; printf("\nprint the contents of array a[]");
i=0; while(a[i]>0) if(a[i]>10) printf("big "); else printf("small "); i++; int a[100]=11, 12, 13, 14, 15, 6, 7, 8, 9, 10, ; int i, n; printf("\nprint the contents of array a[]"); i=0; while(1) if(a[i]<=0) break; if(a[i]>10) printf("big "); else printf("small "); i++; int a[100]=11, 12, 13, 14, 15, 6, 7, 8, 9, 10, ; int b[100]=0,; int i, n; i=0; while(a[i]>0) b[i]=a[i]; i++; // a[] b[] printf("\nprint the contents of array b[]"); i=0; while(b[i]>0) printf("%4d", b[i]); i++;
1 1 1 1 2 1 1 2 1 1 2 2 1 1 1 1 1 2 2 1 3 1 2 2 2 1 1 3 1 1 1 2 3 1 2 3 1 1 1 1 2 2 1 3 1 1 1 2 1 3 1 1 3 1 1 2 2 1 1 3 1 1 3 2 1 1 1 3 1 1 2 3 1
Chapter 9 (1 ) 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 for(i=0;i<1000;i++) a[i]=i; 2 4 2 2 a[] 0 4, 6, 8, 10, 12, 14,,,, 2 3 3 6 3 3 6, 9, 12, 15, 18, 21,,,, 3 5 5 10 5 5 10, 15, 20, 25, 30, 35,,,, 5 7 7 14 7 7 14, 21, 28, 35, 42, 27,,,, 7 11 11
5 5 3 3 9 9 5 5 a[2]=5; 7 3 3 9 9 7 7 a[3]=7 9 3 3 9 9 9 9 11 3 3 9 9 11 11 3 11 5 5 25 25 11 11 a[4]=11 13 3 3 9 9 13 13 3 13 5 5 25 25 13 13 a[5]=13 15 3 3 9 9 15 15 3 17 3 3 9 9 17 17 3 17 5 5 25 25 17 17 a[6]=17 19 3
Chapter 10 FILE *fin; char finname[80]; int c; printf("\nplease enter File name:"); scanf("%s", finname); fin = fopen(finname, "r"); c = fgetc(fin); while(c!= EOF) printf("%c", c); c = fgetc(fin); fclose(fin); c = fgetc(fin); while(c!= EOF) printf("%c", c); c = fgetc(fin);
unsigned char a, b, c; a = 'A'; b = 'B'; c = 'C'; printf("\n%c %c %c ", a, b, c); A B C printf("\n%d %d %d ", a, b, c); 65 66 67 unsigned char a, b, c; a = 65; b = 66; c = 67; printf("\n%c %c %c ", a, b, c); FILE *fin, *fout; char finname[80]; char foutname[80]; int c;
printf("\nplease enter input file name:"); scanf("%s", finname); printf("\nplease enter output file name:"); scanf("%s", foutname); fin = fopen(finname, "rb"); if(fin==null) printf("\ncannot open file:%s", finname); exit(1); fout = fopen(foutname, "wb"); if(fout==null) printf("\ncannot open file:%s", foutname); exit(1); c = fgetc(fin); while(c!= EOF) fputc(c, fout); c = fgetc(fin); fclose(fin); fclose(fout); 23 69 6E 63 6C 75 64 65 3C 73 74 64 69 6F 2E 68 # i n c l u d e < s t d i o h 3E 0D 0A 69 6E 74 20 6D 61 69 6E 28 29 0D 0A 7B > i n t m a i n ( ) 0D 0A 20 20 20 20 69 6E 74 20 69 2C 20 6E 3B 0D i n t i, n ; 0A int i, n;
FILE *fin; char fname[80]; int c; printf("\nplease enter input file name:"); scanf("%s", fname); fin = fopen(fname, "rb"); if(fin==null) printf("\ncannot open file:%s", fname); exit(1); c = fgetc(fin); while(c!= EOF) printf("%02x ", c); c = fgetc(fin); fclose(fin);
Chapter 11 >hoidts<edulcni# )(niam tni ;n, j, i tni int i, j, n; # i i n n t c l m i u a n d i t e n < ( i s ), t d j i, o n h ; > $$$ $$$ $$$ int i, j, k;$$$int a[10]=0,; #include<stidoh>$$$>hoidts<edulcni# $$$)(niam tni $$$ int i, j, k;$$$;,0=]01[a tni 1 6 2 16 3 4 8 5 3 6 ( isprint ) 7 000000 23 69 6E 63 6C 75 64 65 3C 73 74 64 69 6F 2E 68 #include<stdioh
000010 3E 0D 0A 69 6E 74 20 6D 61 69 6E 28 29 0D 0A 7B > 000020 0D 0A 20 20 20 69 6E 74 20 69 2C 6A 2C 6E 2C 6B int i,j,n,k 000030 2C 6C 3B 0D 0A 20 20 20 69 6E 74 20 61 5B 33 30,l; int a[30 000040 5D 5B 33 30 5D 3D 7B 30 2C 7D 3B 0D 0A 0D 0A 20 ][30]=0,; 000050 20 20 70 72 69 6E 74 66 28 22 6E 75 6D 62 65 72 printf("number 000060 3D 22 29 3B 0D 0A 0D 0A 20 20 20 73 63 61 6E 66 ="); scanf 000070 28 22 25 64 22 2C 26 6E 29 3B 0D 0A 0D 0A 20 20 ("%d",&n); 000080 20 66 6F 72 28 69 3D 30 3B 69 3C 6E 3B 69 2B 2B for(i=0;i<n;i++ 000090 29 0D 0A 20 20 20 7B 0D 0A 20 20 20 20 20 20 66 ) f 0000A0 6F 72 28 6A 3D 30 3B 6A 3C 6E 3B 6A 2B 2B 29 0D or(j=0;j<n;j++) 0000B0 0A 20 20 20 20 20 20 7B 0D 0A 09 09 61 5B 69 5D a[i] 000230 20 20 20 7D 0D 0A 0D 0A 20 20 20 72 65 74 75 72 retur 000240 6E 20 30 3B 0D 0A 7D 0D 0A n 0; FILE *fin; char fname[80]; unsigned char line[100]; int c; printf("\nplease enter file name:"); scanf("%s", fname); fin = fopen(fname, "rb"); if(fin == NULL) printf("\ncannot open file: %s", fname); exit(1); c = fgetc(fin); while(c! = EOF) if(c!= 13) else 13 0D 0D 0A c = fgetc(fin); while fclose(fin); c = fgetc(fin); while(c!= EOF) c = fgetc(fin); if(c!= 13)
else 13 ( 0D) 0A FILE *fin1, fin2; char fname1[80], fname2[80]; unsigned char line[100]; int c, d; printf("\nplease enter file name:"); scanf("%s", fname1); printf("\nplease enter file name:"); scanf("%s", fname2); fin1 = fopen(fname1, "rb"); if(fin1 == NULL) printf("\ncannot open file: %s", fname1); exit(1); fin2 = fopen(fname1, "rb"); if(fin2 == NULL) printf("\ncannot open file: %s", fname2); exit(1); c = 0; d = 0; while((c!= EOF) && (d!= EOF)) c = fgetc(fin1); while((c! = EOF)&&(c!= 13)) c = fgetc(fin1); // while loop EOF 13 if(c!= EOF) 13 0D 0D 0A else // d = fgetc(fin2); while((2! = EOF)&&(2!= 13)) d = fgetc(fin2); // while loop EOF 13 if(c!= EOF) 13 0D 0D 0A else //
file1 file2 fclose(fin1); fclose(fin2);
Chapter 12 // oneline int oneline(int n) int i; printf("%4d", i+1); int i, n; printf("\nplease enter number:"); scanf("%d", &n); oneline(i+1); // oneline printf("\n"); int i, j, n; printf("\nplease enter number:"); scanf("%d", &n); for(j=0;j<i+1;j++) printf("%4d", j+1); printf("\n"); int factorial(int n)
int i, fact; fact = 1; for(i=2;i<=n;i++) fact = i*fact; return fact; int square(int n) return n*n; int n; printf("\nplease enter number:"); scanf("%d", &n); printf("\nnumber=%4d factorial = %4d square = %4d ", n, factorial(n), square(n));
Chapter 13 # #### # # # # ## # # # 1 2 3 4 5 2 3 4 5 1 3 4 5 1 2
Chapter 14 -C/C++,
Chapter 15 -?
Chapter 16