Â
In this, we are going to write a program to swap the values of two variables without using an extra variable i.e. Method-2 in C Programming Language.
#include <stdio.h>
void main()
{
//Declaring variables
int a, b;
printf("Enter the two number for a and b to be swapped:\n");
//Taking Inputs
scanf("%d %d", &a, &b);
printf("The values Before Swaping:\na = %d\nb = %d\n", a, b);
//Swapping values
a = a + b;
b = a - b;
a = a - b;
//Printing Swapped values
printf("The values After Swaping:\na = %d\nb = %d\n", a, b);
}
//......Coded by ANANYA MAURYA and MADHESH NAIDU
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP