Swapping two numbers using three different methods

 First method- (using three variables) 

#include<stdio.h>

int main() 

{

int a=10,b=20,c;

c=a;

a=b;

b=c;

printf("%d %d",a,b);

return 0;

}

Second method-(using two variables) 

#include<stdio.h>

int main() 

{

int a=10,b=20;

a=a+b;

b=a-b;

a=a-b;

printf("%d %d",a,b);

return 0;

}

Third method-(using two variables in single line) 

#include<stdio.h>

int main() 

{

int a=10,b=20;

b=a+b-(a=b) ;

printf("%d %d",a,b);

return 0;

}

Comments

Popular posts from this blog

Create account in java |deposit money|withdraw money

Library Management System in python OOPs Concept

List comprehension hackerrank solution in python