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 |
#define prod(a,b) a*b main() { int x=3,y=4; printf("%d",prod(x+2,y-1)); }
main() { int a=10,*j; void *k; j=k=&a; j++; k++; printf("\n %u %u ",j,k); }
Write a program using one dimensional array to assign values and then display it on the screen. Use the formula a[i]=i*10 to assign value to an element.
1 Answers Samar State University,
Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all.
2 Answers Mentor Graphics, Microsoft,
what is variable length argument list?
¦void main() ¦{ ¦int i=10,j; ¦ j=i+++i+++i; ¦printf("%d",j); ¦getch(); ¦} ¦ output:-30 but in same question if we write as- ¦void main() ¦{ ¦int i=10; ¦ int j=i+++i+++i; ¦printf("%d",j); ¦getch(); ¦} ¦ output:-33 why output is changed from 30 to 33. Can any body answer...
main() { extern int i; i=20; printf("%d",sizeof(i)); }
PROG. TO PRODUCE 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
#define clrscr() 100 main() { clrscr(); printf("%d\n",clrscr()); }
void main() { int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location pointed by i; }
How we print the table of 3 using for loop in c programing?
main() { static int a[3][3]={1,2,3,4,5,6,7,8,9}; int i,j; static *p[]={a,a+1,a+2}; for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j), *(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i)); } }