Detailed Print – CSKC
Sign In

Search

siteicon
Code Learning#CPP#7597 Back

Area and Perimeter of a rectangle

Source Code

		 

Click to open popup

Run Output

Enter the length : 23.5
Enter the Breadth : 11.8
area is=277.3
perimeter is=70.6

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.