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 / joshin

main()
{
printf("enter two number");
scanf("%d%d",&a,&b);
printf("swaped result is b=%d\na=%d",b,a);
}

Is This Answer Correct ?    0 Yes 0 No

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

Answer / nikhil godani

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

Is This Answer Correct ?    0 Yes 0 No

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

Answer / amit chauhan

#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 ?    0 Yes 0 No

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

Answer / school

public class hack
{
magic printwall(the web must block);

Is This Answer Correct ?    0 Yes 0 No

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

Answer / harika

main()
{
int a=2,b=3;
a^=b^=a^=b;
printf("%d,%d",a,b);
}

Is This Answer Correct ?    0 Yes 0 No

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

Answer / saurav raj

#include<stdio.h>
#include<conio.h>

void main()
int a,b;
clrscr();
printf("Enter Two number a & b:- ");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("\nA=%d \t B=%d",a,b);
getch();

Is This Answer Correct ?    0 Yes 0 No

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

Answer / swechha

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

if a=5 and b=10 then
a=5-10=(-5)
b=(-5)+10=5
a=5-(-5)=5+5=10

now a=10 & b=5

Is This Answer Correct ?    0 Yes 0 No

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

Answer / prashant

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

Is This Answer Correct ?    0 Yes 0 No

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

Answer / ajith c.k

#include"stdio.h"
int swap(int *,int*);
int main()
{
int a,b;
printf("enter two number");
scanf("%d%d",&a,&b);
swap(&a,&b);
printf("%d\t%d",a,b);
return ;
}
int swap(int *s,int *q)
{

if(*s==*q)
return;
*s^=*q;
*q^=*s;
*s^=*q;
return ;
}

Is This Answer Correct ?    0 Yes 0 No

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

Answer / sur!

void xorSwap (int *x, int *y) {
if (x != y) {
*x ^= *y;
*y ^= *x;
*x ^= *y;
}
}

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Interview Questions

input may any number except 1,output will always 1.. conditions only one variable should be declare,don't use operators,expressions,array,structure

4 Answers   IBM,


What's the total generic pointer type?

0 Answers  


What is modifier & how many types of modifiers available in c?

0 Answers  


What is difference between main and void main?

0 Answers  


In which category does main function belong??

5 Answers  






a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list

0 Answers  


Write a program to find the smallest and largest element in a given array in c language

11 Answers   Microsoft, Vembu,


Can a pointer be volatile in c?

0 Answers  


write a program that declares an array of 30 elements named "income" in the main functions. then cal and pass the array to a programmer-defined function named "getIncome" within the "getIncome" function, ask the user for annual income of 30 employees. then calculate and print total income on the screen using the following function: "void getIncome ( ai []);

0 Answers   TCS,


What is bash c?

0 Answers  


12. Look at the Code: main() { int a[]={1,2,3},i; for(i=0;i<3;i++) { printf("%d",*a); a++; } } Which Statement is/are True w.r.t the above code? I.Executes Successfully & Prints the contents of the array II.Gives the Error:Lvalue Required III.The address of the array should not be changed IV.None of the Above. A)Only I B)Only II C)II & III D)IV

4 Answers   Accenture,


how does the for loop work actually..suppose for the following program how it ll work plz explain to me for(i=5;i>=0;i--) prinf(i--);

19 Answers   RMSI,


Categories