Swapping two numbers (using two variables)
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
clrscr();
printf("Enter two numbers : ");
scanf("%d %d", &a, &b);
printf("\nBefore swapping : \n\n");
printf("a = %d \t b = %d", a, b);
a = a + b;
b = a - b;
a = a - b;
printf("\n\nAfter swapping : \n\n");
printf("a = %d \t b = %d", a, b);
getch();
}
Output:
Enter two numbers : 10 20
Before swapping :
a = 10 b = 20
After swapping :
a = 20 b = 10
-
UpdatedDec 30, 2019
-
Views13,645
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order