Search unanswered questions...
Enter a question here...

How do you write a program in C to swap two variables without using the third one?

[Edit]

Answer

  1. include
  2. include
main() { int a,b; clrscr(); printf("enter the value for a & b\n"); scanf("%d%d",&a,&b); printf("value of a is %d & b is %d before swapping\n",a,b); a=a+b; b=a-b; a=a-b; printf("value of a is %d & b is %d after swapping\n",a,b); getch(); }

Answer

Program for swapping two numbers without using third variable.This programme will work for only integer not for floating.For both the above code is correct one.

fun_swap( int a,int b){ a = a^b; b =a^b; a =a^b; printf( "%d %d", a,b); }


Improve Answer Discuss the question "How do you write a program in C to swap two variables without using the third one?" Watch Question

First answer by Prabhu Durairaj. Last edit by sunilkumar Deshpande. Question popularity: 36 [recommend question]

Research your answer:

Answers.com > Wiki Answers > Categories > Technology > Computers > Computer Software and Applications > How do you write a program in C to swap two variables without using the third one?

Our contributors said this page should be displayed for the questions below. (Where do these come from)
If any of these are not a genuine rephrasing of the question, please help out and edit these alternates.
A sectences for variables?  Program for swap 2 numbers?  How to swap using c program?  Without two variables swap program?  Write a program to swap two numbers?  Swap 2 variables without using temp?  Write a program which employs Recursion?  Swap two variables using third variable?  Program to swap the values of two variables?  Write a perl program to swap two numbers 510?  Write a programm using variables argc and argv?  Swap two numbers without using third variables?  Write a program to which uses strcmp and strcpy?  What is the program to interchange two variables?  C program to swap 2 numbers without using variables?  How do you write a program in C to swap two variables?  How do you swap function using without third variables?  How do you swap two variables without the third variable?  Program to swap two variables without using temp variable?  How can you swap values of two variables using c language?