EmbLogic's Blog

Write a program to reverse the Array?

CODE:

#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,temp,i,j;
printf(“Enter size of Array\n”);
scanf(“%d”,&n);
int a[n];
printf(“Enter Elements \n”);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf(“Elements Are:\n”);
for(i=0;i<n;i++)
{
printf(“%d\t”,a[i]);
}
printf(“\n”);
for(i=0,j=n-1;i<=n/2;i++,j–)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
printf(“Reversed array:\n”);
for(i=0;i<n;i++)
{
printf(“a[%d]=%d\n”,i,a[i]);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>