write a program to swap two variables a=5 , b= 10 without
using third variable

Answers were Sorted based on User's Feedback



write a program to swap two variables a=5 , b= 10 without using third variable..

Answer / nagendra kumar

#include<stdio.h>
main(){
int a,b;

printf("Enter A value: ");
scanf("%d",&a);

printf("\nEnter B value: ");
scanf("%d",&b);


printf("\nThe value of A is:%d",a);
printf("\n The value of B is:%d",b);

a=a+b;
b=a-b;
a=a-b;

printf("\n The value of A is:%d",a);
printf("\n The value of B is:%d",b);
}

Is This Answer Correct ?    19 Yes 4 No

write a program to swap two variables a=5 , b= 10 without using third variable..

Answer / dhanalakshmi

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter the a value"));
scanf("%d",&a);//a=10
printf("enter the b value");
scanf("%d",&b);//b=5
b=b+a;
a=b-a;
b=b-a;
printf("\n The value of A is:%d",a);
printf("\n The value of B is:%d",b);
}

Is This Answer Correct ?    6 Yes 2 No

write a program to swap two variables a=5 , b= 10 without using third variable..

Answer / samruthi

#include<stdio.h>
void main()
{
int a=5,b=10;
printf("The value of A is:%d",a);
printf("\n The value of B is:%d",b);
b=a;
a=b;
a=b+a;

printf("\n The value of A is:%d",a);
printf("\n The value of B is:%d",b);
getch();
}

Is This Answer Correct ?    10 Yes 7 No

write a program to swap two variables a=5 , b= 10 without using third variable..

Answer / nagendra kumar

#include<stdio.h>
main(){
int a,b;

printf("Enter A value: ");
scanf("%d",&a);

printf("\nEnter B value: ");
scanf("%d",&b);


printf("\nThe value of A is:%d",a);
printf("\n The value of B is:%d",b);

a=(a+b)-(b=a);

printf("\n The value of A is:%d",a);
printf("\n The value of B is:%d",b);
}

Is This Answer Correct ?    4 Yes 2 No

write a program to swap two variables a=5 , b= 10 without using third variable..

Answer / shafi.shaik

main()
{
int a,b;
clrscr();
printf("enter a, b Value");
scanf("%d%d",&a,&b);
printf("\n%d",a);
printf("\n%d",b);
b=b-a;
a=a+b;
b=a-b;
printf("\n%d",a);
printf("\n%d",b);
getch();
}

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More C Interview Questions

how to reverse string "Hello World" by using pointers only. Without any temp var

1 Answers  


What is meant by type casting?

0 Answers  


Famous puzzles which are generally asked by companies during interviews ?

1 Answers   3D PLM, Yahoo,


What are header files in c?

0 Answers  


write a program to print data of 5 five students with structures?

0 Answers  






void main() { static int i = 5; if(--i) { main(); printf("%d ",i); } } what would be output of the above program and justify your answer? }

5 Answers   C DAC, CDAC, Infosys, Wipro,


What is #include cctype?

0 Answers  


What does calloc stand for?

0 Answers  


is forign key will be unique key any table or not?

2 Answers  


Which of the following sorts is quickest when sorting the following set: 1 2 3 5 4 1) Quick Sort 2) Bubble Sort 3) Merge Sort

7 Answers  


What is structure in c language?

0 Answers  


HOW TO HANDLE EXCEPTIONS IN C

8 Answers  


Categories