C program to reverse the elements of an array
Simple C program to reverse elements of an array
Code:
#include<stdio.h>#include<conio.h>
void main()
{
int n,a[10],i,j,e;
clrscr();
printf("enter limit : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter number of a[%d] : ",i);
scanf("%d",&a[i]);
}
for(i=0,j=n-1;i<n/2;i++,j--)
{
e=a[i];
a[i]=a[j];
a[j]=e;
}
Printf(“Reversed string: “);
for(i=0;i<n;i++)
{
printf("\n %d ",a[i]);
}
getch();
}
Comments
Post a Comment