Tuesday, June 30, 2015

Swapping elements by function

#include<stdio.h>
///Swapping by function

void swap(int a, int b);

int main()
{
   int x, y;

   printf("Enter the value of x and y:");
   scanf("%d%d",&x,&y);

   printf("Before Swapping\nx = %d\ny = %d\n", x, y);

   swap(x,y);



   return 0;
}

void swap(int a, int b)
{
   int temp;

   temp = a;
   a   = b;
   b   = temp;
 printf("After Swapping\nx = %d\ny = %d\n", a, b);
}

No comments:

Post a Comment