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 / nikhil gupta

# 2 a=a+b;
b=a-b;
a=a-b;

Is This Answer Correct ?    23 Yes 7 No

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

Answer / ramprasad

class Swap
{
static int iValue,jValue,tot;
public static int swap(int A, int B){
tot = A+B;
iValue = tot-B;
jValue = tot-iValue;
return iValue;
//return jValue;
}
public static void main(String[] args)
{
System.out.println(Swap.swap(5,6));
}
}

Is This Answer Correct ?    23 Yes 8 No

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

Answer / raghavendra

a=3;
b=2;
a=a^b;
b=a^b;
a=a^b;
printf("%d%d",a,b);

Is This Answer Correct ?    34 Yes 21 No

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

Answer / rohan

four Types with single statements:

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

2.a^=b^=a^=b;

3.a=a+b;
b=a-b;
a=a-b;

4.a=a*b;
b=a/b;
a=a/b;


rohanraju143@gmail.com from NIT Waramgal

Is This Answer Correct ?    18 Yes 7 No

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

Answer / dally

#include<stdio.h>
int main()
{
int a,b;
printf("Enter values for a,b\n");
scanf("%d %d",&a,&b);

b = b+a;
a= b-a;
b=b-a;
printf("a = %d,b = %d",a,b);

}

Is This Answer Correct ?    18 Yes 11 No

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

Answer / gouttam pradhan

#include<stdio.h>
main()
{
int a,b;
printf("enter two numbers");
scanf("%d%d",&a&b);
a=a+b;
b=a-b;
a=a-b;
printf("swaped valuess= ",);
printf("a=%d",a);
printf("b=%d",b);
getch();
}

Is This Answer Correct ?    6 Yes 0 No

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

Answer / kedar pethe(mitcoe i.t)

a=a*b;
b=a/b;
a=a/b;

Is This Answer Correct ?    15 Yes 11 No

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

Answer / venki

In vb script...............

a=inputbox ("Enter the first value:")

b=inputbox( "Enter the second value:")

msgbox "Before swap a= "&a&" b= "&b
a=cint(a)+cint(b)
b=cint(a)-cint(b)
a=cint(a)-cint(b)
msgbox "After swap a= "&a&" b= "&b

Is This Answer Correct ?    4 Yes 0 No

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

Answer / sams

Two numbers are input through the keyboard into two
locations C and D. Write a program to interchange the
contents of C and D.



#include<stdio.h>

#include<conio.h>
void main( )
{
int a,b,c;
clrscr( );
printf("Enter A: ");
scanf("%d",&a);

printf("Enter B: ");
scanf("%d",&b);

c=a;
a=b;
b=c;

printf("\n The New Value Of A is : %d",a);
printf("\n The New Value Of B is : %d",b);


getch();
}

Is This Answer Correct ?    6 Yes 2 No

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

Answer / thangaraj

a=a^b;
b=b^a;
a=a^b;

Is This Answer Correct ?    13 Yes 10 No

Post New Answer

More C Interview Questions

what is pointer ? what is the use of pointer?

6 Answers   Infosys,


How many header files are in c?

0 Answers  


Why clrscr is used after variable declaration?

0 Answers  


Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.

0 Answers  


What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?

0 Answers  






Write a program to reverse a given number in c language?

0 Answers  


What kind of sorting is this? SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort

3 Answers   Accenture,


consagous technology placement paper

3 Answers   Consagous, Sypra,


write a program to print largest number of each row of a 2D array

0 Answers  


write function to reverse char array ... without using second array

3 Answers  


I just typed in this program, and it is acting strangely. Can you see anything wrong with it?

0 Answers  


int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;

0 Answers  


Categories