Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


write a program to swap Two numbers without using temp variable.

Answers were Sorted based on User's Feedback



write a program to swap Two numbers without using temp variable...

Answer / chandan

a=a+b;
b=a-b;
a=a-b;

Is This Answer Correct ?    1398 Yes 157 No

write a program to swap Two numbers without using temp variable...

Answer / harisharumalla

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("\n Enter the 2 numbers");
scanf("%d%d",&a,&b);
//swaping of 2 numbers without using temp variable
a=a+b;
b=a-b;
a=a-b;
/* or
a=a*b;
b=a/b;
a=a/b;
*/
printf("\n A = %d \n B = %d\n");
getch();
}

Is This Answer Correct ?    603 Yes 119 No

write a program to swap Two numbers without using temp variable...

Answer / abhi

void swap(int *a,int *b)
{
if(*a == *b)
return;
*a^=*b;
*b^=*a;
*a^=*b;
}

Is This Answer Correct ?    461 Yes 195 No

write a program to swap Two numbers without using temp variable...

Answer / prasanna

Swapping two variables in a single line with no temporary
variable..

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

so.. simple..

Prasanna. (prasanna7287@yahoo.co.in)

Is This Answer Correct ?    351 Yes 139 No

write a program to swap Two numbers without using temp variable...

Answer / guest

# include "stdio.h"
main()
{
int a,b;
printf("enter two numbers for swaping");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("a is %d",a);
printf("b is %d",b);
} output:- takea,b value is 2,3 and give answers is3,2

Is This Answer Correct ?    242 Yes 58 No

write a program to swap Two numbers without using temp variable...

Answer / anantha

b=a+b
a=b-a
b=b-a

if a=3 and b=5
then now b=a+b=8
and a=8-a=8-3=5,now a=5
b=8-a=8-5=3,now b=3

so, a=5 and b=3

Is This Answer Correct ?    198 Yes 59 No

write a program to swap Two numbers without using temp variable...

Answer / nagakishorebabu

a=a+b;
b=a-b;
a=a-b;
printf("a %dand b %dis :",a,b);

Is This Answer Correct ?    181 Yes 43 No

write a program to swap Two numbers without using temp variable...

Answer / ravi saini

void main()
{
int a,b;
printf("enter the two numbers");
scanf("%d%d",&a,&b);
a^=b^=a^=b;
printf("%d%d",a,b);//swapped no
}

Is This Answer Correct ?    119 Yes 66 No

write a program to swap Two numbers without using temp variable...

Answer / sree

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("Enter two numbers");
scanf("%d %d",&a &b);
a=a+b;
b=a-b;
a=a-b;
printf("The swapped values are:");
printf("a:%d",a);
printf("b:%d",b);
getch();
}

Is This Answer Correct ?    73 Yes 23 No

write a program to swap Two numbers without using temp variable...

Answer / sweety

main()
{
int a=2,b=3;
a=a+b;
b=a-b;
a=a-b;
printf("%d",&a);
printf("%d",&b);
getch();
}

Is This Answer Correct ?    72 Yes 26 No

Post New Answer



More C Interview Questions

what is the advantage of using SEMAPHORES to ORDINARY VARIABLES???

2 Answers   NSN,


What is a Genralised LInked List?? Please give a detailed explation of it..

1 Answers  


Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)

0 Answers  


What would happen to X in this expression: X += 15; (assuming the value of X is 5)

0 Answers  


What is anagram in c?

0 Answers  






Explain the use of 'auto' keyword in c programming?

0 Answers  


related to rdbms query .

2 Answers  


What is void pointers in c?

0 Answers  


regarding the scope of the varibles;identify the incorrect statement: a.automatic variables are automatically initialised to 0 b.static variables are are automatically initialised to 0 c.the address of a register variable is not accessiable d.static variables cannot be initialised with any expression

1 Answers   TCS,


what is an inline fuction??

2 Answers  


print 1-50 with two loop & two print Statement

2 Answers  


What is that continue statement??

4 Answers  






Categories