How to swap two variables, without using third variable ?
Answers were Sorted based on User's Feedback
Answer / suseela
for ex x=10,y=20
x=x+y=30(i.e 10+20)
y=x-y=10(i.e 30-20)
x=x-y=20(i.e 30-10)
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / shubham
#include<stdio.h>
#imclude<conio.h>
main()
{
int a,b;
printf("enter two number");
scanf("%d%d",&a,&b);
b=a-b;
a=a-b;
b=a+b;
printf("after swaping &d",swap);
getch();
}
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / hamsa
a=a+b;
b=a-b;
a=a-b;
ex a=2, b=4
a=2+4
b=6-4
a=6-2
ANS a=4
b=4
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / debjyoti talukder
a=a+b;
if(a>b)//only the smaller can b subtracted from greater...
b=a-b://...reverse is not possible
else
b=b-a;
a=a-b;
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / swapnil r
Swapping two variables
1. #define SWAP(x,y) x^=y^=x^=y
2. a=a+b;
b=a-b;
a=a-b;
3. use xor to swap
a = a^b
b= a^b
a= a^b
4. a=a*b;
b=a/b;
a=a/b;
Is This Answer Correct ? | 1 Yes | 3 No |
void main() { int i=i++,j=j++,k=k++; printf(“%d%d%d”,i,j,k); }
write a function to give demostrate the functionality of 3d in 1d. function prototye: change(int value,int indexX,int indexY,int indexZ, int [] 1dArray); value=what is the date; indexX=x-asix indexY=y-axis indexZ=z-axis and 1dArray=in which and where the value is stored??
main() { int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1; } a. Runtime error. b. Runtime error. Access violation. c. Compile error. Illegal syntax d. None of the above
main ( ) { static char *s[ ] = {“black”, “white”, “yellow”, “violet”}; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf(“%s”,*--*++p + 3); }
main( ) { static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3,a+4}; int **ptr = p; ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *++ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); ++*ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); }
#define int char main() { int i=65; printf("sizeof(i)=%d",sizeof(i)); }
#define a 10 int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } void foo() { #undef a #define a 50 }
union u { union u { int i; int j; }a[10]; int b[10]; }u; main() { printf("\n%d", sizeof(u)); printf(" %d", sizeof(u.a)); // printf("%d", sizeof(u.a[4].i)); } a. 4, 4, 4 b. 40, 4, 4 c. 1, 100, 1 d. 40 400 4
To reverse an entire text file into another text file.... get d file names in cmd line
plz tell me the solution.......... in c language program guess any one number from 1 to 50 and tell that number within 8 asking question in yes or no...............
write a program to Insert in a sorted list
main() { char *p; printf("%d %d ",sizeof(*p),sizeof(p)); }