Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    C Program to Find Area and Perimeter of a Square

    C Programming Examples


    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:
    10
    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

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.