Exchange two numbers using Function - C

Write a function to exchange the values of two variables say x and y. Assume x and y are defined as global variables.

Solution:

#include <stdio.h>
int x=12,y=23; //global declaration of variables
void exchange()
{
     int t;
     printf("\nValues Before Exchange x=%d, y=%d\n",x,y);
     t=x;
     x=y;
     y=t;
     printf("\nValues After Excahnge x=%d, y=%d",x,y) ;
}
int main()
{
     printf("Enter Value for x : ");
     scanf("%d",&x);
     printf("\nEnter Value for y : ");
     scanf("%d",&y);
     exchange();
     return 0;
}


Output:

exchange two numbers