Javatpoint Logo
Javatpoint Logo

8. C program to print the elements of an array present on odd position

In this program, we need to print the elements of the array which are present in odd positions. This can be accomplished by looping through the array and printing the elements of an array by incrementing i by 2 till the end of the array is reached.

C program to print the elements of an array present on odd position

In the above array, the elements present on odd positions are a, c and e.

ALGORITHM:

  • STEP 1: START
  • STEP 2: INITIALIZE arr[] = {1, 2, 3, 4, 5}
  • STEP 3: length= sizeof(arr)/sizeof(arr[0])
  • STEP 4: PRINT "Elements of given array present on odd position:"
  • STEP 5: SET i=0. REPEAT STEP 6 and STEP 7 UNTIL i<length
  • STEP 6: PRINT arr[i]
  • STEP 7: i=i+2.
  • STEP 8: RETURN 0.
  • STEP 9: END.

PROGRAM:

Output:

Elements of given array present on odd position:
1
3
5
Next TopicC Programs





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA