C-programming - Reversing an array, C program to reverse an array
Reversing an array
This program- reversing an array, reverses the order of the elements in an array.#include<stdio.h> #include<conio.h> void main() { int a[100],i,n; printf("enter no of elements"); scanf("%d",&n); printf("enter the elements of the array") for(i=0;i<=n;i++) scanf("%d",&a[i]); printf("elements in reversed order is ") for(i=n;i>=0;i--) printf("%d",a[i]); }
Array of elements is got from the user through a for loop. Now using another for loop and by decrementing the n value the elements are printed in reverse order.
output
enter the no of elements 5 enter the elements of the array 1 2 3 4 5 elements in reverse order 5 4 3 2 1
The topic on C-programming - Reversing an array is posted by - Sathya
Hope you have enjoyed, C-programming - Reversing an arrayThanks for your time