write a program to swap Two numbers without using temp variable.

Answers were Sorted based on User's Feedback



write a program to swap Two numbers without using temp variable...

Answer / riyaz

int a, b;

printf("a=");
scanf("%d",&a);
printf("b=");
scanf("%d",&b);


printf("a = %d\nb = %d\n",b,a);
return 0;

Is This Answer Correct ?    1 Yes 1 No

write a program to swap Two numbers without using temp variable...

Answer / ragini

#include<stdio.h>
#include<conio.h>
void swap(int a,int b);
void main()
{
int a,b;
swap(a,b);
printf("Enter the 2 nos");
scanf("%d%d",&a,&b);
}
void swap(int x,int y)
{
x=x*y;
y=x/y;
x=x/y;

}

Is This Answer Correct ?    0 Yes 0 No

write a program to swap Two numbers without using temp variable...

Answer / ankur

Check the answer here
http://www.lifengadget.com/lifengadget/program-interchange-two-numbers-without-using-third-variable/

Is This Answer Correct ?    0 Yes 0 No

write a program to swap Two numbers without using temp variable...

Answer / romeld

#include<stdio.h>
main()
{
int a,b;
printf("enter the value of a and b\n");
scanf("%d%d",&a,&b);
printf("before swapping\na=%d\nb=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("after swapping\na=%d\nb=%d\n",a,b);
getch();
}

Is This Answer Correct ?    0 Yes 0 No

write a program to swap Two numbers without using temp variable...

Answer / krishana singh

a=a*b;
b=a/b;
a=a/b;

Is This Answer Correct ?    1 Yes 2 No

write a program to swap Two numbers without using temp variable...

Answer / biren

#include<stdio.h>
void main()
{
int a=2,b=3;
printf("before swap the value is:::");
printf("a=%d\tb=%d",a,b);
b=a+b-(a=b);
printf("after swap the value is:::");
printf("a=%d\tb=%d",a,b);
}

Is This Answer Correct ?    3 Yes 4 No

write a program to swap Two numbers without using temp variable...

Answer / diponkor roy

#include<iostream>
using namespace std;

int main()
{
int x,y;
cin>>x;
cin>>y;
cout<<"You enter"<<x <<" and"<<y<<endl;
x=x*y;
y=x/y;
x=x/y;
cout<<"After swap your number "<<x <<" and"<<y<<endl;
return 0;
}

Is This Answer Correct ?    2 Yes 3 No

write a program to swap Two numbers without using temp variable...

Answer / ratna

#include<stdio.h>
main()
{
int x,y;
printf("\n enter the two numbers:\n");
scanf("%d%d",&x,&y);
y=(x+y)-y;
x=(x+y)-x;
printf("\n x=%d \n y=%d\n");
getch();
}
output: enter the two numbers:10
20
execute the conditions y=30-20=10
x=30-10=20
finally display the output:20 10

Is This Answer Correct ?    0 Yes 1 No

write a program to swap Two numbers without using temp variable...

Answer / manas ranjan(gift)

#include<stdio.h>
void main()
{
int a,b;
printf("enter the numbers");
scanf("%d%d",&a,&b);
printf("before swaping the values are");
printf("a=%d,b=%d",a,b);
void swap(int,int);
swap(a,b);
}
void swap(int a,int b)
{
a=a+b;
b=a-b;
a=a-b;
printf("a=%d,b=%d",a,b);
}

Is This Answer Correct ?    0 Yes 2 No

write a program to swap Two numbers without using temp variable...

Answer / prudhvi

int a, b, c;
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
c = b;
b = a;
a = c;
Console.WriteLine("a={0},b={1}",a,b);
Console.ReadLine();




}

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C Interview Questions

Which of the following is not an infinite loop ? a.while(1){ .... } b.for(;;){ ... } c.x=0; do{ /*x unaltered within theloop*/ ... }while(x==0); d.# define TRUE 0 ... while(TRUE){ .... }

7 Answers   TCS,


Why the use of alloca() is discouraged?

2 Answers   Oracle,


What is the difference between null pointer and wild pointer?

0 Answers  


compute the nth mumber in the fibonacci sequence?

10 Answers   Canon, HPL, Satyam, TCS,


What is external variable in c?

0 Answers  






Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 2. Enter alphanumeric characters and form 2 array alphaets and digits.Also print the count of each array.

0 Answers  


what is difference between ++(*p) and (*p)++

17 Answers   Accenture, HCL, IBM,


In c programming language, how many parameters can be passed to a function ?

0 Answers  


What is difference between main and void main?

0 Answers  


implement general tree using link list

1 Answers   Wipro,


What is the advantage of c?

0 Answers  


6)What would be the output? main() { int u=1,v=3; pf("%d%d",u,v); funct1(&u,&v); pf("%d%d\n",u,v); } void funct1(int *pu, int *pv) { *pu=0; *pv=0; return; } a)1 3 1 3 b)1 3 1 1 c)1 3 0 0 d)1 1 1 1 e) 3 1 3 1

4 Answers  


Categories