Saturday, October 22, 2011

a c program for reverse of an array

#include <stdio.h>
#include <conio.h>
#include <math.h>

int main()
{
    int i,j,temp;
    int a[5]={0};
    for(i=0;i<=5;i++)
    {
                     scanf("%d",&a[i]);
    }
  
    for(i=0,j=5;i<=2;i++)
    {
                            temp=a[i];
                            a[i]=a[j];
                            a[j]=temp;
                            j--;
                          
    }
   
    printf("the resultant reverse: \n");
    for(i=0;i<=5;i++)
    {
                     printf(" %d ",a[i]);
    }
    getch();
    return 0;
}

No comments:

Post a Comment