Write a C++ program to calculate area and perimeter of square and rectangle using function.
Output Example should be
Enter Side of a square: 4
Enter Length and Breadth of Rectangle: 3 6
The Area of a square is: 16
The Area of Rectangle is: 18
The Perimeter of a Square is: 16
The Perimeter of a rectangle is 18
#include <iostream>
using namespace std;
int main()
{
float sideOfsquare;
float lengthR, breadthR;
cout << "\nEnter Side of a square: ";
cin>> sideOfsquare;
cout << "\nEnter Length and Breadth of Rectangle: ";
cin>> lengthR>>breadthR;
cout << "\nThe Area of a square is: " << sideOfsquare*sideOfsquare;
cout << "\nThe Area of Rectangle is: "<< lengthR * breadthR;
cout << "\nThe Perimeter of a Square is: " << sideOfsquare * 4;
cout << "\nThe Perimeter of a Rectangle is: " << (lengthR + breadthR) * 2;
}
Comments
The best
Leave a comment