swap two no without using third variable
Answers were Sorted based on User's Feedback
Answer / srinathsv
Suppose the 2 variables be 'a' & 'b'
Then,do the following steps
a=a-b
b=a+b
a=b-a
eg:Say a=10;b=6.The output should be a=6;b=10
a=a-b=10-6=4
b=a+b=4+6=10
a=b-a=10-4=6
Is This Answer Correct ? | 35 Yes | 5 No |
Answer / thunder
/* swapping two numbers without using temp*/
#include<stdio.h>
int main()
{
int a=10,b=5;
a=a*b;
b=a/b;
a=a/b;
print f("a : %d b: %d",a,b);
}
Is This Answer Correct ? | 12 Yes | 4 No |
Answer / mik30
its very simple question and it can be easily solved by some
logical reasioning ablity...my answer is given below:
#include<stdio.h>
#include<conio.h>
int main()
{
int a=2,b=2;
a=a-b;
b=a+b;
a=b-a;
printf("%d%d",a,b);
getch();
return 0;
}
ad we are from campusmainac group and our core part is
c/c++/php.so if u had any problem in
programming,alogorithm,hacking,networking,windows and Data
structure,come to this site:
http://www.campusmaniac.com/
http://forum.campusmaniac.com/
Is This Answer Correct ? | 8 Yes | 1 No |
Answer / v.bharathi
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nenter a,b value");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("\nafter swapping..\n%d%d",a,b);
getch();
}
Is This Answer Correct ? | 10 Yes | 3 No |
Answer / rivers
ill just write the logic here
a= a xor b
b= b xor a
a= a xor b
Take an example and check for yourself ,it works!
Is This Answer Correct ? | 9 Yes | 3 No |
Answer / ankit
if there are two no as int a,b;
then we could swap these two no's without help of third no
as........>>>>>>
EX-->
int a,b;
a=a+b;
b=a-b;
a=a-b;
Is This Answer Correct ? | 8 Yes | 2 No |
Answer / tejesh49
dim a as integer
dim b as integer
dim c as integer
a=a+b
b=a-b
a=a-b
print a
print b
Is This Answer Correct ? | 3 Yes | 7 No |
how to generate Question paper and how to save pattern of question paper
how exactly is the lngColour used?
create a .dll component operation and use created component in another project. required methods events and properties. connect, add,search,data report
Write a Program in Visual Basic by means of which we can send any data from Visual basic program to any other application running on that machine whether that application supports OLE or not.....
I need help for Source Code & design of my school thesis enrollment system using visual basic 6.0/2008 database MS Access 2007. Please help me friends...Thanks...
swap two no without using third variable
problem no.3 - write a program using two dimentional arrays that compute the sum of data in rows and sum of data in columns of the 3*3 array variable. sample input/output dialog 5 9 8 = 22 3 8 2 = 13 4 3 9 = 16 _____________ 12 20 19
Write a script to delete all the files in a folder except one desired file.
write a program to create a notepad using common dialog control and rich text box.
I have string str="Arts And Props" now i want to replace space in string with null. means i want result as str="ArtsAndProps"
Write a code snippets to find greatest and least of any number of inputs without taking the help of array