Computer Science, asked by jadhavsahil280, 6 months ago

Write a C++ Program to interchange the values of two int , float and char using function overloading.​

Answers

Answered by tripathiakshita48
0

Answer:

C++ Program to interchange the values of two int , float and char using function overloading.​

Explanation:

#include<iostream>

using namespace std;

// Function to interchange int values

void interchange(int &a, int &b)

{

int temp;

temp = a;

a = b;

b = temp;

}

// Function to interchange float values

void interchange(float &a, float &b)

{

float temp;

temp = a;

a = b;

b = temp;

}

// Function to interchange char values

void interchange(char &a, char &b)

{

char temp;

temp = a;

a = b;

b = temp;

}

// Main function

int main()

{

int x = 10, y = 20;

float m = 3.14, n = 2.14;

char a = 'A', b = 'B';

// Before interchange

cout << "Before Interchange : " << endl;

cout << "x = " << x << " y = " << y << endl;

cout << "m = " << m << " n = " << n << endl;

cout << "a = " << a << " b = " << b << endl;

// Interchange the values

interchange(x, y);

interchange(m, n);

interchange(a, b);

// After interchange

cout << "After Interchange : " << endl;

cout << "x = " << x << " y = " << y << endl;

cout << "m = " << m << " n = " << n << endl;

cout << "a = " << a << " b = " << b << endl;

return 0;

}

For more such related questions : https://brainly.in/question/32611467

#SPJ1

Similar questions
Math, 6 months ago