array Initialization and sub-scripting

Array Initialization and Sub-scripting


  • If a is an array, we can write a[expr], where expr is an integral expression, to access an element of the array.
  • We call expr a subscript, or index of a.
  • The expression a[i]can be made to refer to any element of the array by assignment of an appropriate value to the subscript i.
  • eg. a[i+j], a[i-j], a[i+2] 
 
 
Example: Find the minimum among all the data stored in an array.
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
int main() {
int i, min, array[10];

printf("Please Enter 10 Numbers:\n");
for (i = 0; i < 10; ++i)
scanf("%d", &array[i]);

min = array[0];
for (i = 1; i < 10; ++i) {
if (array[i] < min)
min = array[i];
}
printf("The Minimum Number is: %d\n", min);
return 0;
}


Output

Please Enter 10 Numbers:
15 5 7 55 -8 17 -11 25 16 9
The Minimum Number is: -11
Next Post Previous Post
No Comment
Add Comment
comment url