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

if ENTERED FIVE DIGITS DESIGN A PROGRAM THAT WILL FIND CORRESPONDING VALUE FROM ASCII TABLE

1 Answers  


Why header file is used in c?

0 Answers  


What are the main characteristics of c language describe the structure of ac program?

0 Answers  


how can i calculate mean,median,mode by using c program

1 Answers   HCL,


When should I declare a function?

0 Answers  






44.what is the difference between strcpy() and memcpy() function? 45.what is output of the following statetment? 46.Printf(“%x”, -1<<4); ? 47.will the program compile? int i; scanf(“%d”,i); printf(“%d”,i); 48.write a string copy function routine? 49.swap two integer variables without using a third temporary variable? 50.how do you redirect stdout value from a program to a file? 51.write a program that finds the factorial of a number using recursion?

3 Answers  


How can we see the Expanded source code and compiled code for our source program in C?

1 Answers  


Write a programm such that if user enter 11.25 it roundup to 11 but if user enter 11.51 upto 11.99 it will round up to 12 i.e.;convert the floting point value into integer format as explain above..

2 Answers  


can we write a c program with out using main

3 Answers  


There is a 100-story building and you are given two eggs. The eggs (and the building) have an interesting property that if you throw the egg from a floor number less than X, it will not break. And it will always brake if the floor number is equal or greater than X. Assuming that you can reuse the eggs which didn't broke; you got to find X in a minimal number of throws. Give an algorithm to find X in minimal number of throws.

5 Answers   Yahoo,


How do you print an address?

0 Answers   TCS,


What is Heap?

3 Answers  


Categories