xxxxxxxxxx
// Overcomplicating things lol. Try this
#include <stdio.h>
int main()
{
int x, y;
printf("Enter Value of x ");
scanf("%d", &x);
printf("\nEnter Value of y ");
scanf("%d", &y);
int temp = x;
x = y;
y = temp;
printf("\nAfter Swapping: x = %d, y = %d", x, y);
return 0;
}
xxxxxxxxxx
#include<stdio.h>
void main()
{
int x = 10, y = 20;
printf("Before swap x=%d y=%d",x,y);
x=x+y;
y=x-y;
x=x-y;
printf("\nAfter swap x=%d y=%d",x,y);
}
xxxxxxxxxx
#include <stdio.h>
int main()
{
int a, b, temp;
printf("enter the values of a and b: \n");
scanf("%d%d", &a, &b );
printf("current values are:\n a=%d\n b=%d\n", a, b);
temp=a;
a=b;
b=temp;
printf("After swapping:\n a=%d\n b=%d\n", a, b);
}
xxxxxxxxxx
#include <stdio.h>
int main()
{
int x = 20, y = 30, temp;
temp = x;
x = y;
y = temp;
printf("X = %d and Y = %d", x, y);
return 0;
}
xxxxxxxxxx
#include<stdio.h>
void swapping(int, int); //function declaration
int main()
{
int a, b;
printf("Enter values for a and b respectively: \n");
scanf("%d %d",&a,&b);
printf("The values of a and b BEFORE swapping are a = %d & b = %d \n", a, b);
swapping(a, b); //function call
return 0;
}
void swapping(int x, int y) //function definition
{
int third;
third = x;
x = y;
y = third;
printf("The values of a and b AFTER swapping are a = %d & b = %d \n", x, y);
}