C Programming Examples Tutorial Index

C Number Programs

This C example program performs simple mathematical calculations to find the area and perimeter of a rectangle. The perimeter of a rectangle is equal to 2 times the length + width, and its area equals the multiplication of length and width.

Example C Program:
#include <stdio.h>

void main() {
  /* Variable Declaration. */
  float lnth, wdth, perimeter, area;

  /* Taking input of the length of the rectangle from the user */
  printf("Enter the length of the Rectangle:\n");
  scanf("%f", & lnth);
  /* Taking input of the width of the rectangle from the user */
  printf("Enter the width of the Rectangle:\n");
  scanf("%f", & wdth);
  /* Calculate perimeter of the rectangle */
  perimeter = 2 * (lnth + wdth);
  printf("Perimeter of the Rectangle: %0.4f\n", perimeter);

  /* Calculate area of the rectangle */
  area = lnth * wdth;
  printf("Area of the Rectangle: %0.4f\n", area);

Program Output:

Enter the length of the Rectangle:
Enter the width of the Rectangle:
Perimeter of the Rectangle: 260.0000
Area of the Rectangle: 4000.0000

Found This Useful? Share This Page!