Users Online
· Guests Online: 96
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
Swapping of two numbers without third variable
Swapping of two numbers without third variable
You can also swap two numbers without using third variable. In that case C program will be as follows:
-
#include <stdio.h>
-
-
int main()
-
{
-
int a, b;
-
-
printf("Input two integers (a & b) to swap\n");
-
scanf("%d%d", &a, &b);
-
-
a = a + b;
-
b = a - b;
-
a = a - b;
-
-
printf("a = %d\nb = %d\n",a,b);
-
return 0;
-
}
Output of program:
To understand the logic choose the variables 'a' and 'b' as '7' and '9' respectively and then do what is being done by the program. You can choose any other combination of numbers as well. Sometimes it's an excellent way to understand a program.
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.