Javatpoint Logo
Javatpoint Logo

6. C program to print the elements of an array in reverse order

In this program, we need to print the elements of the array in reverse order that is; the last element should be displayed first, followed by second last element and so on.

C program to print the elements of an array in reverse order

Above array in reversed order:

C program to print the elements of an array in reverse order

ALGORITHM:

  • STEP 1: START
  • STEP 2: INITIALIZE arr[] = {1, 2, 3, 4, 5}
  • STEP 3: length= sizeof(arr)/sizeof(arr[0])
  • STEP 4: PRINT "Original Array:"
  • STEP 5: REPEAT STEP 6 and STEP 7 UNTIL i<length
  • STEP 6: PRINT arr[i]
  • STEP 7: i=i+1
  • STEP 8: PRINT new line.
  • STEP 9: PRINT "Array in reverse order"
  • STEP 10: SET i=length-1. REPEAT STEP 11 and STEP 12 UNTIL i>=0
  • STEP 11: PRINT a[i]
  • STEP 12: i=i-1
  • STEP 13: RETURN 0.
  • STEP 14: END

PROGRAM:

Output:

Original array: 
1 2 3 4 5
Array in reverse order:
5 4 3 2 1
Next TopicC Programs




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA