swap two integer variables without using a third temporary
variable?
Answers were Sorted based on User's Feedback
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\n ENTER 2 VALUES : ");
scanf("%d%d",&a,&b);
printf("\n THE VALUES BEFORE SORTING : %d,%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\n THE VALUES AFTER SORTING : %d,%d",a,b);
getch();
}
Is This Answer Correct ? | 40 Yes | 1 No |
the best way what i choose is that : if x=89 , y=-88
x^=y^=x^=y;
this line will swap the above numbers......
thank u
Is This Answer Correct ? | 10 Yes | 5 No |
Answer / sumit salve
a=a+b-(b=a);
or
a=a*b/(b=a);
this will also swap two numbers!!!
Thank You...
Is This Answer Correct ? | 0 Yes | 0 No |
i'll only give u logic #include<stdio.h>
void main() { int a=10,b=20;
printf("b4 swap:a=%d b=%d",a,b);
a=a+b;b=a-b;a=a-b; printf("aftr
swap:a=%d b=%d",a,b); }
from-onkar.koparde@gmail.com
Is This Answer Correct ? | 2 Yes | 4 No |
what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }
What is the exact difference between '\0' and ""
What is the main difference between calloc () and malloc ()?
Write a C Program to display the following menu: Menu 1. Display 2. Copy 3. Append 4. Exit Accept the choice (1-4) from the user, and perform the following tasks: Choice 1: Accept a file name from the user and display the file on screen Choice 2: Accept two file names, and copy first file to the second Choice 3: Accept two file names, and append second file to the first file Choice 4: Terminate the program
1 Answers Accenture, Concor, DMU, Satyam, Syntel, Tora,
What does the c preprocessor do?
Write an implementation of “float stringToFloat(char *str).” The code should be simple, and not require more than the basic operators (if, for, math operators, etc.). • Assumptions • Don’t worry about overflow or underflow • Stop at the 1st invalid character and return the number you have converted till then, if the 1st character is invalid return 0 • Don’t worry about exponential (e.g. 1e10), instead you should treat ‘e’ as an invalid character • Write it like real code, e.g. do error checking • Go though the string only once • Examples • “1.23” should return 1.23 • “1a” should return 1 • “a”should return 0
What are the different types of endless loops?
What is call by reference in functions?
Explain what is the heap?
define string ?
What are the storage classes in C?
what is the output of the following program? main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }