Skip to content

Commit 58c0e1f

Browse files
authored
swap two numbers
Swap two numbers without third variable
1 parent c5c05c2 commit 58c0e1f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int a=10, b=20;
5+
printf("Before swap a=%d b=%d",a,b);
6+
a=a+b;//a=30 (10+20)
7+
b=a-b;//b=10 (30-20)
8+
a=a-b;//a=20 (30-10)
9+
printf("\nAfter swap a=%d b=%d",a,b);
10+
return 0;
11+
}

0 commit comments

Comments
 (0)