create a c++ program with a function named “area” that calculates the area of a rectangle and function named “perimeter”that calculates perimeter of rectangle. Let the user input the data needed for the program.
#include <iostream>
using namespace std;
int area(int length, int width);
int perimeter(int length, int width);
int main()
{
int length, width;
cout << "Enter length: ";
cin >> length;
cout << "Enter width: ";
cin >> width;
cout << "\nArea: " << area(length, width) << "\n";
cout << "Perimeter: " << perimeter(length, width) << endl;
}
int area(int length, int width) {
return length * width;
}
int perimeter(int length, int width) {
return (length + width) * 2;
}
Comments
Leave a comment