C
Programming and Technical
Programming
Program
write a C program two swap two numbers without using temporary variable??
Read Solution (Total 12)
-
- MAIN()
{
PRINTF("ENTER TOW NO")
SCANF("%d%d",&a &b
a=a+b;
b=a-b;
a=a-b;
getch
}
there is key problem so it is not error free but logic is same; - 10 years agoHelpfull: Yes(11) No(1)
- #include
int main(void)
{
int a,b;
printf("Enter two number");
scanf("%d%d",&a,&b);//a=10,b=20
a ^= b;//using XOR ^
b ^= a;
a ^= b;
printf("a=%d b=%d",a,b);//a=20,b=10
getch();
} - 10 years agoHelpfull: Yes(5) No(0)
- main()
{
printf("enter two number");
SCANF("%d%d",&a &b);
a=a*b;
b=a/b;
a=a/b;
} - 10 years agoHelpfull: Yes(2) No(0)
- void main()
{
int a=5,b=6,temp;
a=temp;
b=a;
temp=b;
printf("swaping of two no");
scanf("%d%d%d",&a,&b,&temp);
}
- 10 years agoHelpfull: Yes(1) No(4)
- main()
{
int a,b;
printf("enter two numbers:");
scanf("%d%d",&a,&b);
a=a^b;
b=a^b;
a=a^b;
printf("%d%d",a,b);
getch();
}
Here a,b values converted to binary number and doing xor operation on two values....i think u can understand it....it is another way without using temporary variable... - 10 years agoHelpfull: Yes(1) No(0)
- LOGIC....
a=a+b;
b=a-b;
a=a-b; - 10 years agoHelpfull: Yes(0) No(0)
- #include
#include
void main()
{
clrscr();
int a=10,b=20;
a=a+b;
b=a-b;
a=a-b;
printf("%d %d",a,b);
getch();
} - 10 years agoHelpfull: Yes(0) No(0)
- //Let a=1,b=2
a=b-a; //a=1
b=b-a; //b=1
a=a+b; //a=2
//a=2,b=1
- 10 years agoHelpfull: Yes(0) No(0)
- #include
void main()
{
int a=10,b=20;
a=b-a;
b=b-a;
a=a+b;
printf("%d %d",a,b);
return 0;
} - 10 years agoHelpfull: Yes(0) No(0)
- int main()
{
int a,b;
printf("nenter any 2 numbers");
scanf("%d%d",&a,&b);
printf("nbefore swapingn%d,%d"a,b);
a=a+b;
b=a-b;
a=a-b;
printf("nafter swapingn%d,%d",a,b);
} - 10 years agoHelpfull: Yes(0) No(0)
- #include
#include
void main()
{
int a=10,b=20;
clrscr();
a=a+b;
b=a-b;
a=a-b;
printf("%d %d",a,b);
getch();
} - 10 years agoHelpfull: Yes(0) No(0)
- #include
int main(void)
{
int a,b;
printf("Enter two number");
scanf("%d%d",&a,&b);
b=a+b-(a=b);
printf("a=%d b=%d",a,b);
getch();
}
- 9 years agoHelpfull: Yes(0) No(0)
C Other Question