C Programming Examples Tutorial Index

C Number Programs

This C example program performs simple mathematical calculations to find the area and perimeter of a square. The perimeter of a square is equal to 4 times the length of any of its sides, and its area is equal to multiplied by the length of any side.

Example C Program:
#include <stdio.h>

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

  /* Taking user input */
  printf("Enter the length of the side of the square:\n");
  scanf("%f", & side);

  /* Calculate Perimeter of the square */
  perimeter = 4 * side;
  printf("Perimeter of the Square : %0.4f\n", perimeter);

  /* Calculate Area of the square */
  area = side * side;
  printf("Area of the square : %0.4f\n", area);

Program Output:

Enter the length of the side of the square:
Perimeter of the Square : 40.0000
Area of the square : 100.0000

Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram