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 |
void main() { int *mptr, *cptr; mptr = (int*)malloc(sizeof(int)); printf(ā%dā,*mptr); int *cptr = (int*)calloc(sizeof(int),1); printf(ā%dā,*cptr); }
main() { clrscr(); } clrscr();
main() { int c=- -2; printf("c=%d",c); }
main() { int a=10,*j; void *k; j=k=&a; j++; k++; printf("\n %u %u ",j,k); }
how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1 loop) and maximum 2 variables using C.
19 Answers Cap Gemini, Infosys,
String reverse with time complexity of n/2 with out using temporary variable.
write a c program to print magic square of order n when n>3 and n is odd?
Give a one-line C expression to test whether a number is a power of 2.
Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?
There is a lucky draw held every day. if there is a winning number eg 1876,then all possible numbers like 1867,1687,1768 etc are the numbers that match irrespective of the position of the digit. Thus all these numbers qualify fr the lucky draw prize Assume there is no zero digit in any numbers. write a program to show all the possible winning numbers if a "winning number"is passed as an arguments to the function.
what is brs test reply me email me kashifabbas514@gmail.com
main() { struct date; struct student { char name[30]; struct date dob; }stud; struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year); }