Write a C code to swap 2 numbers without using the 3rd variable?

All QuestionsCategory: C LanguageWrite a C code to swap 2 numbers without using the 3rd variable?
Chetan Shidling Staff asked 5 years ago

I need code.

1 Answers
Chetan Shidling Staff answered 5 years ago

I know how to swap two variables without using a third variable. Take the first variable as 5 and take the second variable as double of 5 say 10.

Code:

#include<stdio.h>

int main()

{

int a = 5, b = 10;

printf(“Number before swapping: a : %d, b : %d”a,b);

a = a + b;

b = a – b;

a = a – b;

printf(“Number after swapping a:%d, b : %d”,a,b);