How to swap two variables, without using third variable ?
Answers were Sorted based on User's Feedback
Answer / deep
let a=5 , b=10
a=a-b
means a=5-10=-5
b=b+a
b=10+(-5)
b=5
a=b-a
a=5-(-5)
a=10
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / d maniteja
let
a=x, b=y our aim is to get output as a=y&b=x;
program:
void main()
{
int a=x,b=y;
a=(a+b)+(a-b);
b=(a+b)-(a-b);
a=a/2;
b=b/2;
printf(("%d %d",a,b);
}
| Is This Answer Correct ? | 0 Yes | 1 No |
without using third variable swap two nos
a=(a+b)-(b-a);
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / gobinath
swap(int *a,int *b)
{
*a=*a-*b;
*b=*a+*b;
*a=*b-*a;
}
| Is This Answer Correct ? | 0 Yes | 1 No |
main() { 41printf("%p",main); }8
write a program for area of circumference of shapes
void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(ā%dā, i); }
main() { int i=5,j=10; i=i&=j&&10; printf("%d %d",i,j); }
#define clrscr() 100 main() { clrscr(); printf("%d\n",clrscr()); }
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.
main() { show(); } void show() { printf("I'm the greatest"); }
func(a,b) int a,b; { return( a= (a==b) ); } main() { int process(),func(); printf("The value of process is %d !\n ",process(func,3,6)); } process(pf,val1,val2) int (*pf) (); int val1,val2; { return((*pf) (val1,val2)); }
void main() { int x,y=2,z; z=(z*=2)+(x=y=z); printf("%d",z); }
#include<stdio.h> main() { register i=5; char j[]= "hello"; printf("%s %d",j,i); }
#define a 10 void foo() { #undef a #define a 50 } int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } explain the answer
main() { printf("\nab"); printf("\bsi"); printf("\rha"); }