Swapping
macro:- #define SWAP(x,y,t) ((t) = (x), (y)=(x), (y)=(t))
#include <stdio.h>
#include <string.h>
void main()
{
int n,temp=0,x,y;
printf("Enter the amount of numbers to be entered:\n");
scanf("%d",&n);
int a[n]; //arrau Creation
//Filling the array
for(int i=0;i<n;i++)
{
printf("Enter the %d number:",i+1);
scanf("%d",&a[i]);
}
printf("Enter the first index:\n");
scanf("%d",&x);
printf("Enter the second index:\n");
scanf("%d",&y);
temp=a[y-1];
a[y-1]=a[x-1];
a[x-1]=temp;
printf("Swapped form:\n");
for(int p=0;p<n;p++)
{
printf("%d\n",a[p]);
}
}
Comments
Post a Comment