Sunday, January 15, 2017

C Program to reverse an array

C Program to reverse an array


Source Code-
#include
int main()
{

int n, i, j, a[100], b[100];

printf("Enter the number of elements in array ");
scanf("%d", &n);

printf("Enter the array elements ");

for (i = 0; i < n ; i++)
scanf("%d", &a[i]);

/*
* Copying elements into array b starting from end of array a
*/

for (i = n - 1, j = 0; i >= 0; i--, j++)
b[j] = a[i];



printf("The Reversed array is ");

for (i = 0; i < n; i++)
printf("%d ", b[i]);

return 0;
}
output-

Available link for download