Definition
• An array is a finite set of variable of the same
data type
• Exampe
2How to use
• Declares:
– The first method:
[number_nember];
– The second method, etc, : self_study
• Access:
[index]
• Example:
int a[10];
a[0] = 3;
a[1] = 7;
int b = (a[0]*3 + a[1])/4;
7 trang |
Chia sẻ: phuongt97 | Lượt xem: 375 | Lượt tải: 0
Nội dung tài liệu Bài giảng Tin học đại cương A: Array - Nguyễn Dũng, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
Array
Lecturer: Nguyen Dung
Faculty of Information Technology
Definition
• An array is a finite set of variable of the same
data type
• Exampe
Index 0 1 2 3 4 5 6 7 8
a 3 5 4 3 8 7 9 12 34
2
How to use
• Declares:
– The first method:
[number_nember];
– The second method, etc, : self_study
• Access:
[index]
• Example:
int a[10];
a[0] = 3;
a[1] = 7;
int b = (a[0]*3 + a[1])/4;
3
Examples
• For an array is declared as follow:
int temperature[7];
• Write a program to input 7 integer numbers into
an array above.
• Determine the maximum value entered and
show the index number for the maximum value
in array above.
4
Solve
void main(){
int temperature[7];
int maximum, index;
for(int i = 0; i < 7; i++){
printf(“Temperature[%d]”, i);
scanf(“%d”, &temperature[i]);
}
maximum = temperature[0]; index = 0;
for(int i = 0; i < 7; i++)
if (temperature[i] > maximum){
maximum = temperature[i];
index = i;
}
printf(“The maximum value is: %d”, maximum);
printf(“This is number %d in the list of number”, %d);
getch();
}
5
Exercises
• Visit to my website to get it
6
The end
The end of course
7
Các file đính kèm theo tài liệu này:
- bai_giang_tin_hoc_dai_cuong_a_array_nguyen_dung.pdf