answersLogoWhite

0


Best Answer

#include<stdio.h>

main()

{

int a,b;

printf("enter the value for a and b\n");

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

display(a,b);

}

display(int x,int y)

{

int temp;

temp=x;

x=y;

y=temp;

printf("%d %d",x,y);

}

User Avatar

Wiki User

βˆ™ 13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

βˆ™ 15y ago

void swap(int *a, int *b)

{

// *a ^= *b means *a = *a XOR *b

*a ^= *b;

*b ^= *a;

*a ^= *b;

}

An example: a = 1101, b = 1010 a ^= b ---> a = 0111 b ^= a ---> b = 1101 a ^= b ---> a = 1010

This answer is:
User Avatar

User Avatar

Wiki User

βˆ™ 13y ago

#include <stdio.h>

#include <conio.h>

void swap(int *d1 , int *d2)

{

int temp;

temp=*d1;

*d1=*d2;

*d2=temp;

}

void main()

{

int a,b;

clrscr();

printf("Enter number a:");

scanf("%d", &a);

printf("\nEnter number b:");

scanf("%d", &b);

swap(&a,&b);

printf("\na contain %d",a);

printf("\nb contain %d",b);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

βˆ™ 11y ago

#include

void swap( int *a, int *b){

int temp = *a;

*a = *b;

*b = temp;

}


int main(){

int a,b;

printf("Enter the two numbers : ");

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

swap(&a, &b);

printf("After swapping; a=%d , b=%d\n", a, b);

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

βˆ™ 11y ago

void main()

{

int a,b,c;

printf("\n enter variables");

scanf("\%d,%d",&a&b);

c=a;

a=b;

b=c;

printf("%d%d",a,b);

}

This answer is:
User Avatar

User Avatar

Wiki User

βˆ™ 11y ago

Here's a function that'll swap any two integers:

void swap(int & x, int & y)

{

if( x y ) return;

x ^= y ^= x ^= y;

}

This answer is:
User Avatar

User Avatar

Wiki User

βˆ™ 13y ago

Why don't you write it and post it here and someone will tell you if it is good or offer good advice.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a C program to swap 2 numbers using 3rd variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the definition for defining the variable?

choosing a variable to represent one of the unspecified numbers in a problem and using it to write expressions for the other unspecified numbers in the problem.


How to write a C program to find largest 2 numbers using pointers?

program to find maximum of two numbers using pointers


How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


Write a shell program using if-the-else to test whether a variable name is a directory or a file?

see : Write_a_shell_program_using_the_if-the-else_to_test_whether_a_variable_name_is_a_directory_or_a_file


Write a program to find the product of two numbers using Halving and Doubling method?

i need this answer


Can you write addition of 2 no program without using third variable?

Yes. int a, b; a= 2; b= 3; a= a+b;


Write a program large number and small number among n numbers by using If statement?

12


What is program in c to swap entered two numbers without using third variable?

The required c program is given below /*Swapping(interchange) the two entered numbers*/ #include&lt;stdio.h&gt; main() { /*Without using third variable*/ int a,b,t; printf("Enter a:"); scanf("%d",&amp;a); printf("Enter b:"); scanf("%d",&amp;b); a=a+b; b=a-b; a=a-b; printf("\n After swapping without using third variable"); printf("\na=%d\nb=%d",a,b); }


Write a C program to find lowest number among ten numbers using for loop?

If you had an array int numbers[10]; you would do it like this: CODE: int lowestnumber = numbers[0]; for(int i = 0; i &lt; 10; i++){ if(numbers[i] &lt; lowestnumber) lowestnumber = numbers[i]; } END CODE I think this should work, and in the end the variable lowestnumber will hold the lowest value in the ten. Hope this helps.


Write a program to swap two numbers using function?

swap (int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; }


Write a C program to find the square of two numbers?

Please visit http://talentsealed.blogspot.com/2009/10/to-find-sqaure-of-numbers-using-c.htmlfor the answer.