To find the area of a rectangle or a square you need to multiply the length and the width of a rectangle or a square. There are different units for perimeter and area. The perimeter has the same units as the length of the sides of rectangle or square whereas the area’s unit is squared.
In this example. I’ll show how to calculate Area and Perimeter of Rectangle in C.
C Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h> #include <stdlib.h> int main() { int b1, b2, area, perimeter; printf("Width: "); scanf("%d", &b1); printf("Height: "); scanf("%d", &b2); area = b1 * b2; perimeter = 2 * (b1 + b2); printf("area = %d\n", area); printf("perimeter = %d", perimeter); return 0; } |