Experiment 18

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Experiment 18

#include <iostream>

using namespace std;

void interchange(int &a, int &b) {

int temp = a;

a = b;

b = temp;

void interchange(float &a, float &b) {

float temp = a;

a = b;

b = temp;

void interchange(char &a, char &b) {

char temp = a;

a = b;

b = temp;

int main() {

int x = 10, y = 20;

float a = 1.5, b = 2.5;


char c1 = 'A', c2 = 'B';

cout << "Before interchange: x = " << x << ", y = " << y << endl;

interchange(x, y);

cout << "After interchange: x = " << x << ", y = " << y << endl;

cout << "Before interchange: a = " << a << ", b = " << b << endl;

interchange(a, b);

cout << "After interchange: a = " << a << ", b = " << b << endl;

cout << "Before interchange: c1 = " << c1 << ", c2 = " << c2 << endl;

interchange(c1, c2);

cout << "After interchange: c1 = " << c1 << ", c2 = " << c2 << endl;

return 0;

o/p:-
#include <iostream>

using namespace std;

int sum(int a, int b) {

return a + b;

double sum(double a, double b) {

return a + b;

int main() {

int int1 = 5, int2 = 10;

double double1 = 5.5, double2 = 10.5;

cout << "Sum of integers: " << sum(int1, int2) << endl;

cout << "Sum of doubles: " << sum(double1, double2) << endl;

return 0;

o/p:_
#include <iostream>

#include <cmath>

using namespace std;

double area(double radius) {

return M_PI * radius * radius;

double area(double length, double width) {

return length * width;

double area(double base, double height) {

return 0.5 * base * height;

int main() {

double radius = 5.0;

double length = 10.0, width = 4.0;

double base = 8.0, height = 5.0;

cout << "Area of Circle: " << area(radius) << endl;

cout << "Area of Rectangle: " << area(length, width) << endl;

cout << "Area of Triangle: " << area(base, height) << endl;
return 0;

o/p:-

You might also like