About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Monday, September 2, 2013

C Program to Reversing an Array Elements in C Programming

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

void main()
{
 int a[30],i,j,n,temp;

 printf("Enter no of elements :");
 scanf("%d",&n);

 /* read n elements in an array  */
 for(i=0 ; i < n ; i++)
  scanf("%d",&a[i]);

 j = i-1;   // j will Point to last Element
 i = 0;     // i will be pointing to first element 

 while(i < j)
 {
 temp = a[i];
 a[i] = a[j];
 a[j] = temp;
 i++;             // increment i and decrement j 
 j--;
 }
  /* Print out the Result of Insertion */

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

   getch();
}

No comments: