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 |
write a c program thal will find all sequences of length N that produce the sum is Zero, print all possible solutions?
What is wrong with this code such that it doesnt produce the input reversed? #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char Space = ' '; char LineOfText; float count; LineOfText = getchar(); while ((LineOfText = getchar()) != '/n'); { count = strlen(LineOfText) - 1; while (count >= 0) { putchar(LineOfText[count]); count--; } } getchar(); return 0; }
Difference between goto, long jmp() and setjmp()?
Sir,please help me out with the output of this programme:- #include<stdio.h> #include<conio.h> void main() { int a=18,b=12,i; for(i=a<b?a:b;a%i||b%i;i--); printf("%d %d",i); }
How old is c programming language?
How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?
code for selection sort?
What does it mean when a pointer is used in an if statement?
how can make variable not in registers
Why is event driven programming or procedural programming, better within specific scenario?
What is pointer to pointer in c with example?
Give the Output : * * * * * * * * * *