Write a C program to calculate the perimeter of a rectangle

Description: Take the height and width of a rectangle as input, and print its perimeter.

Hint:

  • Perimeter = 2 x (height + width).

C program to calculate the perimeter of a rectangle

#include <stdio.h>

int main(void) {
    float height, width, perimeter;

    printf("Enter height and width: ");
    scanf("%f %f", &height, &width);

    perimeter = 2 * (height + width);
    printf("Perimeter = %.2f\n", perimeter);
    return 0;
}

Output:

Output of the above program is

Enter height and width: 5 3.5
Perimeter = 17.00

How it works

  • The user enters the height and width.
  • We use the formula 2 * (height + width) and print the result.

Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.