# ch7 - 6 cfw D h Z 2 120 h Z 120 2 int age1 age2 age3 age119...

This preview shows pages 1–11. Sign up to view the full content.

± + {+ :ãD hZˆ¸ª 120 2 2 120 ¸ int age1, age2, age3, …. .. age119, age120 age1=0; age2=0; printf(“%d\n”, age1); …… printf(“%d\n”, age2); age120=0; …... scanf(“%d”,&x); printf(“%d\n”, age120); while((x>0)&&(x<121)){ if(x==1) age1 += 1; else if(x==2) age2 += 1; …… else if(x==120) age120 += 1; scanf(“%d”,&x); } E ix [

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
§7.1 2 ˆZ ˆ ¸ª* int a[10]; 2 a[0], a[1], a[2], …... a[9] 2 int i=3, j=2, a[10]; 2 a[i], a[i+2], a[i+j], …… 2 2 2 2 2 X ³9
main() { int a[120], x, i, n=0; for(i=0; i<120; i++) a[i]=0; scanf(“%d”,&x); while( (x>0) && (x<121) ){ a[x-1] = a[x-1] + 1; n++; scanf(“%d”,&x); } printf(“Total people =%d\n”, n); for(i=0; i<120; i++) printf(“%d years old=%d\n”, i+1, a[i]); } v [ ] ˆ1 ì¹ª 120 2 a[0], a[1], a[2], …. .. a[119] 1 2 3 120 2 2 ˜V ¸

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
int a[10]; float b[5]; char c[20]; a[0], a[1], …... a[9] b[0], b[1], …... b[4] c[0], c[1], …... c[19] 2 2
int a[3]={1 2 3 2 5}; float b[2]={3.14 2 5.18}; char c[5]={‘a’, ‘b’, ‘c’, ‘d’, ‘e’}; d int a[]={1 2 2 2 3 2 4 2 5}; { int b[10]={1 2 2};

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
] int a[20]; a[0] a[1] a[2] a[17] a[18] a[19] ….. 2
[ 2 7.1] 2 a[0] 2 a[9] 2 0~9 T ‘ [ 9876543210 main() { int i,a[10]; for (i=0; i<=9; i++) a[i]=i; for(i=9; i>=0; i--) printf(“%d ”, a[i]); }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
[ 2 7.2] [ Fibonacci [ 20 2 main() { int i; int f[20]={1,1}; for (i=2; i<20; i++) f[i]=f[i-2]+f[i-1]; /* 2 f[2] 2 f[19] */ for (i=0; i<20; i++) { if (i%5==0) printf(“\n”); /* [ 5 2 */ printf(“%12d ”, f[i]); } } 1 2 1 2 2 2 3 2 5 2 8 2 …… f[0], f[1], f[2], f[3], f[4], f[5], ……f[19]
[ 2 ] 5 [ [ ˜!6;{+ °Zˆ ¸ª*@ ù 1 2 8 2 5 2 15 2 0 0 2 1 2 5 2 8 2 15 2 1 5 8 0 15 [ [ [ 4 2 [ ... 1 8 5 15 0 1 8 5 15 0 1 5 8 15 0 1 5 8 15 0

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
] n T ¹ª* n-1 2 2 j n-j T[ w / ] 1 2 n-j [ 2 7.3]T 10 0s main() { int a[11]; /* a[0] 2 , 10T a[1] 2 a[10] 2 */ int i,j,t; printf(“intput 10 numbers : \n”); for (i=1; i<11; i++) scanf(“%d”,&a[i]); printf(“\n”);
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 36

ch7 - 6 cfw D h Z 2 120 h Z 120 2 int age1 age2 age3 age119...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online