Function Overloading

#include<iostream>
using namespace std;

/* First function with the name "perimeter" and return 'long' */
long perimeter(int r) {
	return 2*(22/7)*r;
}

/* Second function with the name "perimeter" and return 'double' */
double perimeter(int l , int w) {
	return 2*(l+w);
}

/* Third function with the name "perimeter" and return 'int' */
int perimeter(int a, int b, int c) {
	return a+b+c;
}


int main() {
	cout << "Perimeter of Circle: " << perimeter(5) << endl;
	cout << "Perimeter of Rectangle: " << perimeter(10,20) << endl;
	cout << "Perimeter of Triangle: " << perimeter(5,10,15) << endl;
	return 0;
}


/* Output */
Perimeter of Circle: 30
Perimeter of Rectangle: 60
Perimeter of Triangle: 30

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!