Write a program to swap two numbers using function (pass the pointers).


Input


#include <stdio.h>
void swap(int *x,int *y)
{
    int t;
     t   = *x;
    *x   = *y;
    *y   =  t;
}

int main()
{
    int x,y;

    printf("Enter x : ");
    scanf("%d",&x);
    printf("Enter y : ");
    scanf("%d",&y);

    printf("Before Swapping : x:%d , y:%d\n",x,y);

    swap(&x,&y);

    printf("After  Swapping : x:%d , y:%d\n",x,y);

    return 0;
}




Output


Enter x : 56
Enter y : 12
Before Swapping : x:56 , y:12
After  Swapping : x:12 , y:56

No comments:

Post a Comment