Write a program to swap two numbers using temporary variables and functions (call by value
#include <stdio.h>
int a, b;
void Swap(int x, int y)
{
int temp;
temp = x;
b = x;
a = temp;
}
main(void)
{
int temp;
a=20; b=30;
printf("\nSwapping Method Using temp:\tBefore Swapping: a = %d,\tb=%d",a,b);
temp=a;
a = b;
b = temp;
printf("\n\t\t\t\tAfter Swaping : a = %d,\tb=%d",a,b);
a=20; b=30;
printf("\n\n\nSwapping Method Using Swap Function by Value:");
printf("\n\tBefore Swapping: a = %d,\tb=%d",a,b);
swap(a,b);
printf("\n\ttfter Swaping : a = %d,\tb=%d",a,b);
return(0);
}
Comments
Leave a comment