17.WAP to swap a number without using temp variable.

 

/ 4 ways to swap numbers without using temp variable //

 

#include<stdio.h>

int i,j;

void main()

{

printf("Enter value of i : ");

scanf("%d",&i);

printf("Enter value of j : ");

scanf("%d",&j);

 

//1st Way//

/*

i=i+j;

j=i-j;

i=i-j;

*/

 

//2nd Way//

/*

i=i*j;

j=i/j;

i=i/j;

*/

 

//3rd Way//

/*

i=i+j-(j=i);

*/

 

//4th Way//

i=i*j/(j=i);

 

 

printf("Swapped values are i : %d & j : %d\n",i,j);

}

Comments