In this C program, we will calculate the perimeter and area of rectangle. To find the perimeter and area of rectangle, we will first take length and breadth of rectangle as input from user using scanf function and then calculate area and perimeter of rectangle using following formulae.
Required Knowledge
- Perimeter of Rectangle = 2 x (length + width)
- Area of Rectangle = length x width
C program to find the perimeter and area of rectangle
#include <stdio.h> int main() { float length, width, area, perimeter; printf("Enter length of Rectangle\n"); scanf("%f", &length); printf("Enter width of Rectangle\n"); scanf("%f", &width); perimeter = 2 * (length + width); printf("Perimeter of Rectangle : %f\n", perimeter); area = length * width; printf("Area of Rectangle : %f\n", area); return 0; }
Output
Enter length of Rectangle 3.5 Enter width of Rectangle 5 Perimeter of Rectangle : 17.000000 Area of Rectangle : 17.500000
Related Topics