write a program to swap two numbers without using temporary
variable?
Answers were Sorted based on User's Feedback
Answer / it diploma student
let a and b be the variables
a=a+b
b=a-b
a=a-b
if we take a=5 and b = 7 then
a = 5+7 = 12
b = 12-7 = 5
a = 12-5 = 7
hence swaped...
| Is This Answer Correct ? | 26 Yes | 3 No |
Answer / guest
[code]
main()
{
int a=10;
int b=20;
printf("a = %d\nb = %d\n",a,b);
a =a+b; b=a-b; a=a-b; // This is first way.
a =a*b; b=a/b; a=a/b;
printf("a = %d\nb = %d\n",a,b);
}
[/code]
[code]
main()
{
int a=10;
int b=20;
printf("a = %d\nb = %d\n",a,b);
a =a*b; b=a/b; a=a/b; //This is second way
printf("a = %d\nb = %d\n",a,b);
}
[/code]
| Is This Answer Correct ? | 19 Yes | 2 No |
Answer / sam
let a and b be variables
a^=b^=a^=b;
by performing this logic from right hand side we can swap
two variables
| Is This Answer Correct ? | 6 Yes | 5 No |
Why functions are used in c?
How can I do serial ("comm") port I/O?
Which of the following about the C comments is incorrect ? a.commentscan go over multiple lines b.comments can start any where in the line c.a line can contain comments with out any language statements d.comments can occur within comments
int array[]={1,2,3,4,5,6,7,8}; #define SIZE (sizeof(array)/sizeof(int)) main() { if(-1<=SIZE) printf("1"); else printf("2"); }
The __________ attribute is used to announce variables based on definitions of columns in a table?
How is a null pointer different from a dangling pointer?
34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?
why little endian and big endian came?y they using differently? y they not used commonly ?wt is application of little and big ?
What is pointer and structure in c?
what is the return value (status code) of exit() function.... what the arguments(integer value) passed to it means....
Write a pro-gramme to determine whether the number is even or odd?
What does 1f stand for?