C PROGRAM TO SWAP TWO NUMBERS BY USING CALL BY REFERENCE
#include <stdio.h>
int swap (int *, int *);
int main()
{
int a, b;
printf("\nEnter Two Values:\n");
scanf("%d %d", &a, &b);
printf("Before Swapping:\n");
printf("a = %d\nb = %d\n", a, b);
swap(&a, &b);
printf("After Swapping:\n");
printf("a = %d\nb = %d", a, b);
return 0;
}
int swap (int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
//OUTPUT
Enter Two Values:
3
14
Before Swapping:
a = 3
b = 14
After Swapping:
a = 14
b = 3
Enter Two Values:
200
900
Before Swapping:
a = 200
b = 900
After Swapping:
a = 900
b = 200
Comments
Post a Comment