Home Tutorial Datastructure Inverse of an array in C

 
 

Inverse of an array in C
Posted on: April 30, 2010 at 12:00 AM
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

Related Tags for Inverse of an array in C:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.