Need a project done?

C++ Programming Developer

Search This Blog

Function "swap" to exchange two values by passing arguments by reference to the function in C++


/*
Write a program by defining a function "swap" to exchange two values by passing arguments by reference to the function.
*/

#include <iostream>
using namespace std;

void swap (double &, double &);

int main()
{
int Num1,Num2;
cout<<"Number1 = "; cin>>Num1;
cout<<"Number2 = "; cin>>Num2;
swap(Num1,Num2);
cout<<endl;
cout<<"Number1 = " << Num1 << endl;
cout<<"Number2 = " << Num2 << endl;
return 0;
}

void swap(double &Num1, double &Num2)
{
int Temp = Num1;
Num1 = Num2;
Num2 = Temp;
}

No comments:

Post a Comment

"Don't let anyone ever make you feel like you don't deserve what you want."