Inverse of an array in C


 

Inverse of an array in C

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.

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

Ads