Thursday, 4 November 2021

C Program for Swapping using call by value method

C Program for Swapping using call by value method


Program:-        
#include <stdio.h>
#include<conio.h>
void swap(int, int);
int main()
{
int x, y;
printf("Enter the value of x and y\n");
scanf("%d %d", &x, &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;
}
void swap(int a,  int b)
{
int temp;   
temp = b;
b = a;
a = temp;
printf("Values of a and b is %d  %d\n", a, b);
}
 

Output:-
Enter the value of x and y : 4  6
Before Swapping x = 4 y =6
After Swapping  x = 6 y = 4

No comments:

Post a Comment

google-site-verification: google18ae80885fc3d876.html