The logic to print the alternate elements in an array is very simple. We use the for loop to iterate through the array starting with the first element. Instead of increment the for loop variable by 1, increment it by 2.
C program to print alternate numbers in an array - Source code
/* C Program to Print the Alternate Elements in an Array
int i, j, temp;
printf("enter the element of the array \n");
for (i = 0; i < 12; i++)
printf("Alternate elements of the entered array \n");
for (i = 0; i < 12; i += 2)
printf( "%d\n", array[i]) ;
enter the element of the array
Alternate elements of the entered array
1. First, user is asked to enter the elements of the array. Here Array of 12 numbers is declared, however you can choose this number of your choice.
2. The elements are stored in the array at each indices using the for loop.
3. In order to print the alternate numbers of the array, start the loop with 0 and increment it by 2 with every iteration.