//Program to swap two numbers without using 3rd number
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
clrscr();
printf("Enter two integers values\n");
scanf("%d%d", &a, &b);
// let a = 11, b = 13
printf("The numbers before swapping are\n");
// Printing of a = 11 and b = 13
printf("1st Number = %d\n2nd Number = %d\n\n",a,b);
a = a + b; // a = 11 + 13 = 24
b = a - b; // b = 24 - 13 = 11
a = a - b; // a = 24 - 11 = 13
printf("The numbers after swapping are\n");
//Printing of a = 13 and b = 11
printf("1st Number = %d\n2nd Number = %d",a,b);
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.