1 / 15

int a,b,c,d,e,f,g,h,..., aa,ab,...,zx,zy,zz ; a = 1; b = 2;

一般宣告變數方式 ( 沒有陣列 的日子 ). int a,b,c,d,e,f,g,h,..., aa,ab,...,zx,zy,zz ; a = 1; b = 2;. 宣告大量變數. scanf ("%i%i%i%i", &a, &b, &c, &d ); d = a+b+c;. 以 陣列 方式宣告變數. 1000 個元素. int a[1000] ; a[0] = 1; a[1] = 2; a[ ] = 66;. scanf ("%i%i%i%i", &a[0],&a[1],&a[2],&a[3] );. Array 陣列.

hua
Download Presentation

int a,b,c,d,e,f,g,h,..., aa,ab,...,zx,zy,zz ; a = 1; b = 2;

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 一般宣告變數方式 (沒有陣列的日子) int a,b,c,d,e,f,g,h,..., aa,ab,...,zx,zy,zz; a = 1; b = 2; 宣告大量變數 scanf ("%i%i%i%i", &a, &b, &c, &d); d = a+b+c; 以陣列方式宣告變數 1000個元素 int a[1000]; a[0] = 1; a[1] = 2; a[] = 66; scanf ("%i%i%i%i", &a[0],&a[1],&a[2],&a[3]);

  2. Array 陣列 int days ; 宣告句子 days= 28; 賦值句子 printf ("%i", days); 輸出句子 scanf ("%i", &days); 輸入句子

  3. for (i=1;;i++) days = 31; days[ 1] = 31; days[ 2] = 31; days[ 3] = 31; days[ 4] = 31; days[ 5] = 31; days[ 6] = 31; ... days[10] = 31; days[11] = 31; days[12] = 31; [i]

  4. for (i=1;i<=12;i++) printf("%i",); printf("%i", days[ 1]); printf("%i", days[ 2]); printf("%i", days[ 3]); printf("%i", days[ 4]); printf("%i", days[ 5]); printf("%i", days[ 6]); ... printf("%i", days[10]); printf("%i", days[11]); printf("%i", days[12]); [i]

  5. for (i=1;i<=12;i++) scanf("%i",); scanf("%i", &days[ 1]); scanf("%i", &days[ 2]); scanf("%i", &days[ 3]); scanf("%i", &days[ 4]); scanf("%i", &days[ 5]); scanf("%i", &days[ 6]); ... scanf("%i", &days[10]); scanf("%i", &days[11]); scanf("%i", &days[12]); [i]

  6. for (i=0; i<1000; i++) a[i]=i; for (i=0; i<1000; i++) a[i]=1000-i; for (i=0; i<1000; i++) a[i]=2*i; for (i=0; i<1000; i++) a[i]=2*i+1;

  7. int score[40]; // 40個分數 char grade[40]; // 40個等級 grade[0] = ; grade[1] = ; for (i=0;;i++){ if (score___>=50) grade___='P'; else grade___ = 'F'; } for (i=0;i<40;i++){ if (score[i]<=20) grade[i]='E'; else if (score[i]<=40) grade[i]='D'; else if (score[i]<=60) grade[i]='C'; else if (score[i]<=80) grade[i]='B'; else _____________; }

  8. 輸出畫面: Q: 輸入整數 (1-999): 34 A: thirty four 算法 algorithm: 1. 準備兩個陣列 units[] 、 tens[] 2. 使用者輸入整數 (n) 3. 若 n<20 則輸出文字 (______[n]) 4. 否則 (利用__及__) 把 n 分柝為 個位 unit digit 及十位 tens digit 輸出適當文字 literals文字: 01-10 one two three four five six seven eight nine ten 11-15 eleven twelve thirteen fourteen fifteen 16-19 sixteen seventeen eighteen nineteen 20-90 twenty thirty forty fifty sixty seventy eighty ninety

  9. 1. sum of first n integers 首n個整數的和 1+2+3… int i, sum=0; for (i=1;i<=10;i++) sum = _____________; 2. factorial of n: 首n個整數的積 123… int i, factorial=1; for (i=1;i<=10;i++) factorial =____________; 3. alphabets: 字母 char ch; 65 A 66 B … 90 Z for (ch=___;ch<=___;ch++) printf ("%d %c\n", ch, ch); 97 a 98 b … 122 z for (ch=___;ch<=___;ch++) printf ("%d %c\n", ch, ch);

  10. 3. shift left 左移/上移 a[0] = a[1] = a[2] = a[__]; a[__]; a[__]; for (i=0;i<9;i++) a[___] = a[___]; 4. shift right 右移/下移 a[1] = a[2] = a[3] = a[__]; a[__]; a[__]; for (i=__;i___;i___) a[___] = a[___]; 當i=9, a[9]=a[__]; 當i=8, a[8]=a[__]; 當i=1, a[1]=a[__];

  11. 5. swapping x,y 互換 int x=100, y=50, t; 6. swapping a[0],a[9]互換 int a[10], t; t = __; x = __; y = __; t = a[__]; a[__] = a[__]; a[__] = t; 7. reverse 倒轉(數值) for (i=0;i<__;i++){ } 8. reverse 反轉/倒轉(列印) for (i=9;i____;i--) printf ("%d\n", a[i]); t = a[i]; a[i] = a[___]; a[___] = t; for (i=0;i<10;i++) printf ("%d\n", a[___]);

  12. 9. 陣列的應用 (a) char animals[__][3]={"猴","雞","狗","豬","鼠","牛", "虎","兔","龍","蛇","馬","羊"}; yy=1980; printf ("%s\n", animals[yy______]); (b) char monthname[__][4] ={"?","Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec"}; mm=9; printf ("%s\n", monthname[____]); (c) char cdow[___][4] ={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};

  13. (d) char cnum[___][___] ={"○","一","二","三","四","五","六","七","八","九"}; n=24; x = y = printf ("%s十%s\n", cnum[__], cnum[__]); (e) int maxday[13] ={0, 31,28,31,30,31,30,31,31,30,31,30,31}; do{ printf ("Enter mm,dd "); scanf ("%i%i", &mm, &dd); }while (mm<1 || mm>12 || dd<1 || dd>31);

  14. (f) char zodiac[__][__]={"山羊", "水瓶","雙魚","白羊","金牛","雙子","巨蟹", "獅子","處女","天秤","天蠍","人馬","山羊"}; int zday[__]={0, 20,19,21,21,21,22,23,24,23,23,22,22}; Q: mm dd ? 2 22 A: 雙魚 Q: mm dd ? 2 10 A: 水瓶 z = mm; if(dd<... ... printf ("zodiac = ___\n", zodiac[___]);

  15. 統計(0-9) int i, n, count[10]={0}; for (i=0;i<10;i++) count[__]=0; do{ scanf("%i", &n); }while(1); if (n>=0 && _____) count[___]++; for (i=0;i<10;i++) printf("%i : %i \n", ___, count[__]);

More Related