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.
using namespace std;
float length , breadth , areaOfTheReactangle;
cout<<"Enter the length and breadth of the rectangle separated by a space"<<endl;
areaOfTheReactangle = length * breadth; //Calculating the area of the rectangle
cout<<"The area of the rectangle is"<<endl<<areaOfTheReactangle;
Enter the length and breadth of the rectangle separated by a space
The area of the rectangle is
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.
program by tutorialsinhand.com
About the Author
- 🔭 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 :