Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Write a program to interchange two variables without using
the third variable?

Answers were Sorted based on User's Feedback



Write a program to interchange two variables without using the third variable?..

Answer / guest

#include<stdio.h>
void main()
{
int x,y;
printf("enter x and y");
scanf("%d%d",&x,&y);
x=x+y;
y=x-y;
x=x-y;
printf("elements after swapping :%d,%d",x,y);
}

Is This Answer Correct ?    185 Yes 32 No

Write a program to interchange two variables without using the third variable?..

Answer / jisha. k.a

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter two no");
scanf("%d%d",&a,&b);
a=a-b;
b=a+b;
a=b-a;
printf("After chanching no is =\n");
printf("a=%d b=%d",a,b);
getch();
}

Is This Answer Correct ?    34 Yes 16 No

Write a program to interchange two variables without using the third variable?..

Answer / vinay tiwari

void main()
{
int a,b;
printf("enter two no ");
scanf("%d%d",&a,&b);
printf("a=%d and b=%d",a,b);
a=a^b;
b=a^b;
a=a^b;
printf("a=%d and b=%d",a,b);
getch();
}

Is This Answer Correct ?    22 Yes 13 No

Write a program to interchange two variables without using the third variable?..

Answer / saravanan j (srm universi

you can apply it on any language?!

x = x xor y
y = x xor y
x = x xor y

* 1 year ago

Source(s):
Self Expierince

Is This Answer Correct ?    18 Yes 12 No

Write a program to interchange two variables without using the third variable?..

Answer / debasis nayak

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the value of A and B");
scanf("%d %d",&a,&b);
b=(a+b-a=b);
printf("After interchange value are %d %d",a,b);
getch();
}

Is This Answer Correct ?    11 Yes 13 No

Write a program to interchange two variables without using the third variable?..

Answer / genius

#include <stdio.h>
#include <conio.h>
main()
{
int a,b,temp;
clrscr();
printf("enter two numbers:");
scanf("%d,%d",&a,&b);
printf("values of a and b are %d,%d \n",a,b);
temp=a;
a=b;
b=temp;
printf("swapped values of a and b are %d,%d", a,b);
getch();
}

Is This Answer Correct ?    4 Yes 6 No

Write a program to interchange two variables without using the third variable?..

Answer / tom macdonald

#include<stdio.h>
void main()
{
int x,y;
printf("enter x and y: ");
scanf("%d%d",&x,&y);
x^=y;
y^=x;
x^=y;
printf("elements after swapping: %d,%d\n",x,y);
}

Is This Answer Correct ?    29 Yes 32 No

Write a program to interchange two variables without using the third variable?..

Answer / raghavendra

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter two no");
scanf("%d%d",&a,&b);
a=a*b;
b=a/b;
a=a/b;
printf("After chanching no is =\n");
printf("a=%d b=%d",a,b);
getch();
}

Is This Answer Correct ?    6 Yes 9 No

Write a program to interchange two variables without using the third variable?..

Answer / pari

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("Enter two no");
scanf("%d%d",&a,&b);
a=a*b;
b=a/b;
a=a/b;
printf("After chanching no is =\n");
}

Is This Answer Correct ?    4 Yes 7 No

Write a program to interchange two variables without using the third variable?..

Answer / vijay r15

using many ways we can
perform
#include<stdio.H>
void main()
{
int a=10,b=20;
b=a+b-(a=b);
//or use a^=b^=a^=b;
//or use a=a+b;b=a-
b;a=a-b;
//or use a^=b; b^=a;
a^=b;
printf("%d%d",a,b);
}

Is This Answer Correct ?    2 Yes 5 No

Post New Answer

More C Interview Questions

Is anything faster than c?

0 Answers  


what is the difference b/w compiler and debugger?

2 Answers   Assurgent,


What is the use of function overloading in C?

0 Answers   Ittiam Systems,


compute the nth mumber in the fibonacci sequence?

10 Answers   Canon, HPL, Satyam, TCS,


How can a program be made to print the name of a source file where an error occurs?

0 Answers  


print the table 5 in loops

3 Answers  


Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)

0 Answers  


Is void a keyword in c?

0 Answers  


Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.

0 Answers  


What is the difference between realloc() and free()

1 Answers  


Explain the difference between getch() and getche() in c?

0 Answers  


Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

0 Answers  


Categories