Upcoming SlideShare
×

# ตัวแปรชุดและตัวแปรกลุ่มอักขระ

288 views

Published on

กลุ่ม 5

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
288
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
1
0
Likes
0
Embeds 0
No embeds

No notes for slide

### ตัวแปรชุดและตัวแปรกลุ่มอักขระ

1. 1. 1. 1 (One Dimensional Array) [] subscripttype array-name[n];typearray-namen
2. 2. char number[5];int time[3];float interest[2]; number, time interest subscriptscanf(“%d”,&time[1]);printf(“%fn”,interest[0]); 2(time[1]) time 1( interest[0])interest
3. 3. char number[5];5x1 = 5 char 5number[0], number[1], number[2], number[3] number[4]number 1000
4. 4. int time[3]; 3x2 = 6 int3 time[0], time[1] time[2] time2000time[0] 2000+(0x2) = 2000time[1] 2000+(1x2) = 2002time[2] 2000+(2x2) = 2004
5. 5. float interest[2]; 2x4 = 8 float 2 interest[0] interest[1] interest3000interest[0] 3000+(0x4) =3000 interest[1]3000+(1x4) = 3004
6. 6. 2. 2 (TwoDimensional Array) []2 Matrix 2
7. 7. type array-name[r][c];typearray-namerc
8. 8. int score[3][2]; 3x2 = 6 scorescore[0][0] score[0][1]score[1][0] score[1][1]score[2][0] score[2][1]char person[10][5][80];int incomes[3][5][2];float marks[2][4][20];
9. 9. 3. (Array Initialization) declare 1char msg1[ ] = “Give value for x”;int x1[ ] = {10,2,8};float y1[ ] = {12.8,11.3,9.2,6.35};
10. 10. 2char msg2[ ][40] = {{“SOONTORN”},“BANGKOK”},{“AMORN”},{“CHONBURI”}, {“PRAPAI”}, {“KHONKAEN”}};int x2[ ][3] = {{10,2,8},{5,15,7}};float y2[ ][4] = {12.8,11.3,9.2,6.35,2.28,31.3,19.2,86.5, 12.0,17.43,7.12,62.3};
11. 11. 2 1 1 5#include<stdio.h>void main( ) {int room_no[ ] = {22, 18, 20, 24, 21};int total = 0, n = 0;do { total = total + room_no[n];printf(“Room %d has %3d pupilsn”,n+1,room_no[n]);n++;} while(n<5);printf(“ = = = n”); printf(“Total no is %3d pupilsn”,total);
12. 12. (arrays) (string)
13. 13. 1) 100 100int k1, k2, k3, …, k100; /*k1, k2, k3, …, k100 100 */ 100 subscriptint k[100]; /* 1 k*/2) (table) 23)
14. 14. 1 (arrays variables) (subscript)
15. 15. 1.11) 1 (one dimensionarrays single dimension arrays) 1 (subscript) 1 a[20], b[100], name[30] salary[20]
16. 16. 2) (multi-dimension arrays) (subscript) 22 3 - 2 (two dimension arrays) (subscript) 2 a[2][4], b[3][4], name[5][30] - 3 (three dimension arrays) (subscript) 3 a[2][3][4], b[3][4][5]
17. 17. 2 (declaration ofarrays)1) 1 (declaration of one dimensionarrays)type int, float, char, doublearraynamesize
18. 18. 1 5.1 int s[20]; 2 bytes 2040 bytes
19. 19. 5.2 char p[20]; 1 bytes 2020 bytes
20. 20. 5.3 float t[20]; 4 bytes 20 80 bytes
21. 21. 2) 2 (declaration of two dimension arrays)type int, float, char, doublearraynamen row) 0, 1, 2, …, n-1m column)
22. 22. 2 int r[3][2]; 2 (table) n = 0, 1, 2 m = 0, 12 bytes 6
23. 23. 1 2 1 = (size) 2 = n*m int r[3] [2]; n =3, m = 2 = 3*2 = 6 r[0][0], r[0][1], r[n-1][m-1] 6
24. 24. 3) 3(declaration of three dimension arrays) type arrayname [n] [m] [p];type int, float, char, doublearraynamen 1 0, 1, 2, …., n-1m 2 0, 1, 2, …., m-1p 3 0, 1, 2, …., p-1
25. 25. 3 = n*m*p3 float a[2][2][3]; n = 2 , m = 2, p = 3 = 2*2*3 = 12
26. 26. Column 0 Column 1 1 2 3 1 2 3Row 0 a[0][0][0] a[0][0][1] a[0][0][2] a[0][1][0] a[0][1][1] a[0][1][2]Row 1 a[1][0][0] a[1][0][1] a[1][0][2] a[1][1][0] a[1][1][1] a[1][1][2] 4 bytes 12 4*12 = 48 bytes
27. 27. (initializing arrays)1) 1( 1 type arrayname[size] = { value list };
28. 28. 2( 2 type arrayname[n][m] = { value list };value list , (comma) { } 5.6 int a[10] ={10, 20, 30, 40,50, 60, 70, 80, 90, 100};
29. 29. (table)4 bytes = 4*15 = 60 bytes
30. 30. 2) 1( 1char arrayname[size] = “string constant”; 2( 2char arrayname[n][m] = {“string constant”}; string constants , (comma) 5.8 char s[12] = “ASIAN GAME”;
31. 31. null character
32. 32. 2province [0] 1 NAKHONPANOMprovince [1] 2 SAKON NAKHON province [2] 3 MOOKDAHANprovince [0][0] province [0] 1 Nprovince [1][2] province [1] 3 K
33. 33. for while do while for
34. 34. 11252627 612839