Program for to reverse array of integer. Following program reverses array. If array like
arr[0] = 11
arr[1] = 22
arr[2] = 33
then reverse of this array is
arr[0] = 33
arr[1] = 22
arr[2] = 11
#include<stdio.h>
void main()
{
int no, i, j, arr[100], temp[100];
printf("Enter Total No. of Elements : ");
scanf("%d", &no);
printf("Enter Elements : ");
for (i = 0; i < no ; i++)
scanf("%d", &arr[i]);
for (i = no - 1, j = 0; i >= 0; i--, j++)
temp[j] = arr[i];
for (i = 0; i < no; i++)
arr[i] = temp[i];
printf("\nReverse Array : ");
for (i = 0; i < no; i++)
printf("%d ", arr[i]);
}
0 comments :
Post a Comment