answersLogoWhite

0

#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

13y ago

Still curious? Ask our experts.

Chat with our AI personalities

JudyJudy
Simplicity is my specialty.
Chat with Judy
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
More answers

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();

}

User Avatar

Wiki User

14y ago
User Avatar

#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(); }

User Avatar

Wiki User

16y ago
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