swap two no without using third variable

Answers were Sorted based on User's Feedback



swap two no without using third variable..

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

swap two no without using third variable..

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

swap two no without using third variable..

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

swap two no without using third variable..

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

swap two no without using third variable..

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

swap two no without using third variable..

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

swap two no without using third variable..

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

Post New Answer

More Visual Basic Code Interview Questions

Write a code snippets to find greatest and least of any number of inputs without taking the help of array

1 Answers   Infosys, Wipro,


Write a script to delete all the files in a folder except one desired file.

0 Answers  


how to generate Question paper and how to save pattern of question paper

2 Answers  


write a program to create a notepad using common dialog control and rich text box.

1 Answers  


how exactly is the lngColour used?

0 Answers  






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...

1 Answers  


swap two no without using third variable

7 Answers  


create a .dll component operation and use created component in another project. required methods events and properties. connect, add,search,data report

0 Answers  


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.....

1 Answers  


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

4 Answers   CSS,


I have string str="Arts And Props" now i want to replace space in string with null. means i want result as str="ArtsAndProps"

1 Answers  


Categories