Calculate Area and Perimeter of the rectangle

The length & breadth of a rectangle are input through the keyboard. Write a program in C to calculate the area & perimeter of the rectangle.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
    float length, breadth;

	printf("Enter the length of rectangle\t:");
	scanf("%f",&length);
	printf("Enter the breadth of rectangle\t:");
	scanf("%f",&breadth);

	printf("\nArea of rectangle      = %f",length * breadth);
	printf("\nPerimeter of rectangle = %f\n",2*(length + breadth));

	getch();
}

Output

Enter the length of rectangle   :5
Enter the breadth of rectangle  :7

Area of rectangle      = 35.000000
Perimeter of rectangle = 24.000000

Explanation

In the above program, length and breadth of rectangle are entered by the user at runtime and stored in their respective variables. Area of rectangle is calculated using the formula
Area of rectangle = length * breadth
There are two ways to accomplish the task of calculating and printing the area. First one is to store the result in a variable and then print its value. Second one is to calculate the area inside printf() statement itself and print.
Here, we have used the second one.
printf("\nArea of rectangle = %f",length * breadth);
Here, first of all, (length * breadth) operation is performed and is replaced by the value obtained. And then, that value is printed.

Similarly, perimeter of rectangle is calculated using the formula:
Perimeter of rectangle = 2*(length + breadth)