Initialize the elements of array to the even integers from 2 to 20 : Array Initializing « Array « C Tutorial






#include <stdio.h>
#define SIZE 10

int main()
{   
   int s[ SIZE ]; 
   int j; 

   for ( j = 0; j < SIZE; j++ ) { 
      s[ j ] = 2 + 2 * j;
   } 

   for ( j = 0; j < SIZE; j++ ) {   
      printf( "%7d%13d\n", j, s[ j ] );
   } 

   return 0; 

}
0            2
      1            4
      2            6
      3            8
      4           10
      5           12
      6           14
      7           16
      8           18
      9           20








7.2.Array Initializing
7.2.1.Initializing an array in declaration
7.2.2.Initializing an array using for loop
7.2.3.Initialize the elements of array to the even integers from 2 to 20