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...

# 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...

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 ? 22 Yes 8 No

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

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...

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...

#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...

#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...

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...

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...

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...

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

 Is This Answer Correct ? 13 Yes 10 No

More C Interview Questions

What are directives in c?

What is the difference between null pointer and void pointer

What is indirection? How many levels of pointers can you have?

What is void main ()?

Is it possible to run using programming C for Java Application?

what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }

What is the scope of static variable in c?

what are bit fields in c?

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

Are c and c++ the same?

write a c program to find the roots of a quadratic equation ax2 + bx + c = 0

What does calloc stand for?

Categories