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() { int i=5,j=6,z; printf("%d",i+++j); }
main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); }
int DIM(int array[]) { return sizeof(array)/sizeof(int ); } main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr)); }
main(int argc, char *argv[]) { (main && argc) ? main(argc-1, NULL) : return 0; } a. Runtime error. b. Compile error. Illegal syntax c. Gets into Infinite loop d. None of the above
main( ) { int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) { printf(“%d” ,*a); a++; } p = a; for(j=0; j<5; j++) { printf(“%d ” ,*p); p++; } }
Write a single line c expression to delete a,b,c from aabbcc
Is the following code legal? struct a { int x; struct a b; }
void main() { int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location pointed by i; }
main() { clrscr(); } clrscr();
struct Foo { char *pName; char *pAddress; }; main() { struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); obj->pName = malloc(100); obj->pAddress = malloc(100); strcpy(obj->pName,"Your Name"); strcpy(obj->pAddress, "Your Address"); free(obj); printf("%s", obj->pName); printf("%s", obj->pAddress); } a. Your Name, Your Address b. Your Address, Your Address c. Your Name Your Name d. None of the above
WAP to display 1,2,3,4,5........N
Write a program to model an exploding firecracker in the xy plane using a particle system