Monday, 24 May 2021

Write a program in C to swap two numbers using function

 Write a program in C to swap two numbers using function






#include 
#include 

void swap(int x, int y)
{
    x = x + y;
    y = x - y;
    x = x - y;
    printf("\nAfter Swapping: x = %d, y = %d", x, y);
}
int main()

{
    int x, y;
    printf("Enter Value of x : ");
    scanf("%d", &x);
    printf("\nEnter Value of y : ");
    scanf("%d", &y);
    swap(x, y);

    return 0;
}

Output:



Share:

Related Posts:

0 comments:

Post a Comment