write a program to swap Two numbers without using temp variable.
Answers were Sorted based on User's Feedback
Answer / joshin
main()
{
printf("enter two number");
scanf("%d%d",&a,&b);
printf("swaped result is b=%d\na=%d",b,a);
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / amit chauhan
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("\n Enter the 2 numbers");
scanf("%d%d",&a,&b);
//swaping of 2 numbers without using temp variable
a=a+b;
b=a-b;
a=a-b;
/* or
a=a*b;
b=a/b;
a=a/b;
*/
printf("\n A = %d \n B = %d\n");
getch();
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / school
public class hack
{
magic printwall(the web must block);
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / harika
main()
{
int a=2,b=3;
a^=b^=a^=b;
printf("%d,%d",a,b);
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / saurav raj
#include<stdio.h>
#include<conio.h>
void main()
int a,b;
clrscr();
printf("Enter Two number a & b:- ");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("\nA=%d \t B=%d",a,b);
getch();
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / swechha
a=a-b
b=a+b
a=b-a
if a=5 and b=10 then
a=5-10=(-5)
b=(-5)+10=5
a=5-(-5)=5+5=10
now a=10 & b=5
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ajith c.k
#include"stdio.h"
int swap(int *,int*);
int main()
{
int a,b;
printf("enter two number");
scanf("%d%d",&a,&b);
swap(&a,&b);
printf("%d\t%d",a,b);
return ;
}
int swap(int *s,int *q)
{
if(*s==*q)
return;
*s^=*q;
*q^=*s;
*s^=*q;
return ;
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sur!
void xorSwap (int *x, int *y) {
if (x != y) {
*x ^= *y;
*y ^= *x;
*x ^= *y;
}
}
Is This Answer Correct ? | 1 Yes | 1 No |
simple c program for 12345 convert 54321 with out using string
What is the use of the function in c?
write a c program to add two integer numbers without using arithmetic operator +
how can we Declare a variable in c without defining it.
Tell us the difference between these two : #include"stdio.h" #include<stdio.h> define in detial.
WHAT IS MAXIMUM SIZE OF AN ARRAY IN C LANGUAGE?
8 Answers Carphone Warehouse, IBM, SAS,
How can I read and write comma-delimited text?
#include <stdio.h> int main() { if ("X" <"x") printf("X smaller than x "); } my question is whats the mistake in this program? find it and please tell me..
How can I do serial ("comm") port I/O?
write a fuction for accepting and replacing lowercase letter to'Z' with out using inline function.
Write a c program to Find the name that you entered is male name or female name? Such as Sunjay is name of male and Payal is name of female
What is context in c?