How to swap two number by using third variable in Array?

Below code will help you to do swap of two number in array
#include<stdio.h>
#include<conio.h>
main ()
{
int a[2],i,x;
clrscr();
printf(“Enter two number”);
for(i=0;i<2;i++)
{
scanf(“%d”,&a[i]);
}
x=a[0];
a[0]=a[1];
a[1]=x;
{
for(i=0;i<2;i++)
printf(“%d\n”,a[i]);
}
getch();
}

After Running Program 🙂

 

Leave a Reply