Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Swap the values of variables Program in C++ and C with flowchart 

Swap the values of variables Program in C++ and C with the flowchart 

In this tutorial, we will learn about the followings;

  1. Flowchart to Swap the values of variables 
  2. Program in C++ to swap the values of variables 
  3. Program in C to swap the values of variables 

Flowchart to Swap the values of variables 

flowchart and program to swap the values of variables

Figure: flowchart and program to swap the values of variables.

Program in C++ to swap the values of variables 

#include<iostream>
using namespace std;
int main()
{
float first_veri,Second_veri,Temp_veri;
cout<<"Enter value of 1st variable: ";
cin>>first_veri;
cout<<"Enter value of 2nd veriable: ";
cin>>Second_veri;
Temp_veri=first_veri;
first_veri=Second_veri;
Second_veri=Temp_veri;
cout<<"After swaping the values in both veriables:"<<endl; 
cout<<"1st veriable: "<<first_veri<<endl;
cout<<"2nd veriable: "<<Second_veri<<endl;
return 0;
}

Output

swaping of variables in cpp

figure: swapping of variables.

Program in C to swap the values of variables 

#include <stdio.h>
int main()
{
      double oneNumber, twoNumber, temporarynumber;
      printf("Enter first number:\n ");
      scanf("%lf", &oneNumber);
      printf("Enter second number:\n ");
      scanf("%lf",&twoNumber);
      temporarynumber = oneNumber;
      oneNumber = twoNumber;
      twoNumber = temporarynumber;
      printf("\nAfter swapping, values in 1st variable wiil be = \n%.2lf\n", oneNumber);
      printf("After swapping, values in second veriable = \n%.2lf", twoNumber);
}

Output

swaping of variables in cpp

Figure: swapping of variables in CPP.