Write a program to interchange two variables without using
the third variable?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
What is that continue statement??
Explain Linker and Loader
What is the difference between local variable and global variable in c?
what is c
Do you know pointer in c?
What is call by reference in functions?
Can you explain the four storage classes in C?
Why string is used in c?
How can you avoid including a header more than once?
Can we declare variables anywhere in c?
a function gets called when the function name is followed by a a) semicolon (;) b) period(.) c) ! d) none of the above
Why use int main instead of void main?