#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;
}
#include<stdio.h>
int main()
{
int a=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a+b;//a=30 (10+20)
b=a-b;//b=10 (30-20)
a=a-b;//a=20 (30-10)
printf("\nAfter swap a=%d b=%d",a,b);
return 0;
}
#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);
}