C++ program to find the area of a rectangle
In this chapter of C++ program tutorial out task is:
-
Write a C++ program to take length and breadth of the rectangle as an user input and displaying the area of the rectangle
C++ program to calculate the area of the rectangle
Below is the C++ program to take length and breadth as an user input and then calculating and displaying the area of the rectange.
#include<iostream>
using namespace std;
int main()
{
float length , breadth , areaOfTheReactangle;
cout<<"Enter the length and breadth of the rectangle separated by a space"<<endl;
cin>>length>>breadth;
areaOfTheReactangle = length * breadth; //Calculating the area of the rectangle
cout<<"The area of the rectangle is"<<endl<<areaOfTheReactangle;
return 0;
}
OUTPUT :
Enter the length and breadth of the rectangle separated by a space
2.3 3.0
The area of the rectangle is
6.9
EXPLANATION:
In the above C++ program:
-
The compilation starts from the main function (here int main())
-
Then three 4 bits each memory space is created for the float data type (assuming to be 32/64 bit system)
-
Then the compiler accepts input for the "length" and "breadth"
-
Then the "areaOfTheRectangle" is calculated by the formula and the output the required value
-
The program terminates at the "return 0" statement but returning 0 in the output screen as int main requires a return type.
You can see the above code execution and output in codeblocks IDE:
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Sayantan Bose
- š Iām currently working on DS Algo skills
- š± Iām currently learning web develeopement
- šÆ Iām looking to collaborate with Oppia
- š« Reach me at https://www.linkedin.com/in/sayantan-bose-14134a1a6/
- š Pronouns: his/him
Page Views :
Published Date :
Jul 24,2020