Code Learning#CPP#7597
Back
Area and Perimeter of a rectangle
Source Code
Run Output
Code Understanding
This program calculates the area and perimeter of a rectangle.
• #include allows input and output commands.
• float l, b; creates two variables to store the length and breadth.
• cin >> l >> b; takes input values from the user.
• area = l * b; calculates the area using the formula length × breadth.
• peri = 2 * l + 2 * b; calculates the perimeter using the formula 2 × (length + breadth).
• cout displays the area and perimeter.
• return(0); ends the program.
