Array_Revision
Array_Revision
1 2 3 4 5
int i,a[100];
for(i=0; i<100; i=i+1){
Method 1
if(i%2==0) a[i] = 0;
else a[i] = 1;
} 9
Arrays: Some Example Programs
▪ Create an integer array of size 100
▪ Initialize elements with even index as 0
Incrementing the
▪ Initialize elements with odd index as 1 loop counter by 2
int i,a[100];
Method 2,
for(i=0; i<100; i=i+2){
This for loop will run
without if-else a[i] = 0; 50 times. Each
iteration will assign
a[i+1] = 1; values to 2 elements,
one at odd index, one
} at even index
10
Greek origin word:
palin = again,
Arrays: Some Example Programs dromos = direction