answersLogoWhite

0


Best Answer

#include<stdio.h>

void main()

{

int a,b,t;

printf("enter the values of two varaible");

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

t=a;

a=b;

b=t;

printf("the exchanged values are",b,a);

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

Swapping variables is accomplished using a temporary variable. For example, if A and B are integers, you can swap their values using the following code:

// Initialize A and B

int A = 5;

int B = 7;

// Create our temporary variable

int temp;

// Perform the swap

temp = A;

A = B;

B = temp;

// Print the results

cout << "A: " << A << " B: " << B << endl;

/*mycfiles.wordpress.com

Exchange of value of 2 variable with temporary variable*/

#include<stdio.h>

#include<conio.h>

void main()

{

int a,b,temp;

clrscr();

printf("\nEnter the value for a & b");

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

temp=a;

a=b;

b=temp;

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

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

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

#include<stdio.h> #include<conio.h> void main() { int a,b,c; printf("Enter the value of A"); scanf("%d",&a); printf("Enter the value of B"); scanf("%d",&b); c=a; a=b; b=c; printf("The value of A is %d",a); printf("The value of B is %d",b); getch(); }

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to exchange the value of two variables?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Program to exchange the value x and y using 3 variables?

temp = x; x = y; y = temp;


How are constants and variables different?

Constants are values that remain constant and cannot be changed once they are assigned a value. Variables, on the other hand, can have different values assigned to them and their value can be changed throughout the program. Constants provide a fixed value, while variables provide flexibility and allow for changes in value.


How do you write a program in c to swap two variables without using the add and multiplication?

int varA, varB; int tmp; // common way to swap 2 variables in the same type; tmp = varA; // store the original value of varA varA = varB; // assign A with B varB = tmp; // B now has the original value of varA


Write a program using recursion which should take two values and display 1st value raised to the power of second value?

Write a program using recursion which should take two values and display 1st value raised to the power of second value.


What are continuous and discrete variables?

the value of variables is determined by the equation, discrete variables have absolute single value while the continuos have a range value


What is constant variables?

Variables are items, which change their values during the execution of a program. Constants do not change the value during the execution of a program.


Is eliminating variables from equations equal to find the value of the variables?

No, but eliminating variables is one of several ways to find the value of variables in a system of equations.


What are independent variables and dependent variables in math?

Independent variables are the input value of a function (usually x) and dependent variables are the output value of the function (usually y).


What is the difference between constants and variables?

A variable is a quantity which changes its value through out the program or its lifetime. But a constant is a quantity which does not change its value through out its life time. There are 5 basic constants.


What is the difference between variables and constants in java?

constant is does not change the value of during the excution of programvariable it changes the value during the excution of program


How do variables and symbollic names differ?

Variables are storage areas that hold data that can vary during the execution of a program. A symbolic name is the name given to any entity in a program, including variables, constants, functions, procedures and various other stuff.


How do you write a program in C that variables change value with each other?

void main() { //variable declaration int a; int b; printf("\n Enter the first value"); scanf("%d",&amp;a); printf("\n Enter the second value"); scanf("%d",&amp;b); a=a+b; b=a-b; a=a-b; printf("\n After swap the value"); printf("\n value of A=%d",a); printf("\n value of A=%d",b); getch(); }