16. Program to swap the values of three variables with using fourth variable.

Chapter 4: 

Input And Output

Programming Exercise

Problem # 16:

Write a program to swap the values of three variables with using fourth variable.

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int n1, n2, n3, n4;
    cout<<"Enter three numbers : ";
    cin>>n1>>n2>>n3;
    n4 = n1;
    n1 = n2;
    n2 = n3;
    n3 = n4;
    cout<<"Values after swapping : ";
    cout<<n1<<"\t"<<n2<<"\t"<<n3<<endl;
    return 0;
}

Let me know in the comment section if you have any question.

Previous Post:
15. Program that inputs x, y coordinates for two points and computes the distance between two points.

Comments