Home Tutorial Datastructure Inverse of an array in C

 
 

Share on Google+Share on Google+
Inverse of an array in C
Posted on: April 30, 2010 at 12:00 AM
Advertisement
In this tutorial you will know how to inverse an array in c language. There are three function in this given example one for reading the array element, second for writing on console and last for inverse of an array.

Code:

#include<stdio.h>
#include<conio.h>
void main()
 {
  void read(int *,int);
 void   display(int *,int);
 void  inverse(int *,int);

 int a[6],i;
 clrscr();
 read(a,6);
 display(a,6);
 inverse(a,6);
 display(a,6);
 getch();
 }

 void read(int c[],int i)
  {
	int j;
	printf("Enter six element for an array \n");
	for(j=0;j<i;j++)
	scanf("%d",&c[j]);
  }
  void display(int d[],int i)
  {
	int j;
	printf("Element in array are : \n");
	for(j=0;j<i;j++)
	printf("%d  ",d[j]);
	printf("\n");
  }
 void inverse(int x[],int k)
 {
  int i,temp;
  k--;
  for(i=0;i<(k/2);i++)
	{
	 temp=x[i];
	 x[i]=x[k];
	 x[k]=temp;
	 k--;
	}
  }

Output:

Download this code
Advertisement

Related Tags for Inverse of an array in C:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 30, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com