Business Studies, asked by prernaj1977, 7 months ago

write the program to input three numbers and swap them as this : second number gets the value of first to second number and third number gets the value of third number and third number​

Answers

Answered by Garg5911
2

Answer:

HEY MATE DESCRIBED YOUR QUESTION WITH FULL EXPLANTION PLEASE MARK ME AS BRAINLIEST

Explanation:

Here we will see a program to swap two numbers using a temporary third variable. The steps are as follows:

1. User is asked to enter the value of first and second number. The input values are stored in first(num1) and second(num2) variable.

2. Assigning the value of first variable to the third variable.

3. Assigning the value of second variable to the first variable.

4. Assigning the value of third variable to the second variable.

Example: Program to swap two numbers

#include <iostream>

using namespace std;

int main()

{

int num1, num2, temp;

cout<<"Enter 1st Number: ";

cin>>num1;

cout<<"Enter 2nd Number: ";

cin>>num2;

//displaying numbers before swapping

cout<<"Before Swapping: First Number: "<<num1<<" Second Number: "<<num2;

//swapping

temp=num1;

num1=num2;

num2=temp;

//displaying numbers after swapping

cout<<"\nAfter Swapping: First Number: "<<num1<<" Second Number: "<<num2;

return 0;

}

Output:

C++ Swapping Numbers

Similar questions