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 |
#include<stdio.h> int SumElement(int *,int); void main(void) { int x[10]; int i=10; for(;i;) { i--; *(x+i)=i; } printf("%d",SumElement(x,10)); } int SumElement(int array[],int size) { int i=0; float sum=0; for(;i<size;i++) sum+=array[i]; return sum; } output?
What is the purpose of 'register' keyword in c language?
write a C program, given number is double without using addt ion and multiplication operator?ex:n=6,ans=12,pls send me ans to goviseenu@gmail.com
void main() { int x=25,y=32; clrscr(); x=x++ + y++; y=++x + ++y; printf("%d%d",x,y); }
List some basic data types in c?
Consider a language that does not have arrays but does have stacks as a data type.and PUSH POP..are all defined .Show how a one dimensional array can be implemented by using two stacks.
how to get the starting address of file stored in harddisk through 'C'program.
How do you write a program which produces its own source code as its output?
What is the difference between char a[] = "string"; and char *p = "string"; ?
14 Answers Adobe, Honeywell, TCS,
How do you determine a file’s attributes?
What is the difference between a function and a method in c?
sir, i cannot find the way how to write aprogram by using array on queue