Easy Geometric Calculations: Rectangle and Circle Area and Perimeter

The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.

Introduction

Geometry plays a fundamental role in various fields, including engineering, architecture, and design. Understanding how to calculate the area and perimeter of a rectangle and the area and circumference of a circle is essential for solving practical problems. In this article, we will guide you through the process of writing a program in the C programming language to perform these calculations. By inputting the length and breadth of a rectangle and the radius of a circle through the keyboard, you can quickly obtain the area and perimeter of the rectangle, as well as the area and circumference of the circle.

Calculating Rectangle Area and Perimeter

Before we delve into the implementation, let’s briefly discuss how to calculate the area and perimeter of a rectangle. The area (A) of a rectangle is given by the product of its length (L) and breadth (B):

Area of Rectangle (A) = Length (L) * Breadth (B)

The perimeter (P) of a rectangle is calculated by adding the lengths of all its sides:

Perimeter of Rectangle (P) = 2 * (Length (L) + Breadth (B))

Calculating Circle Area and Circumference

For the circle, we’ll calculate its area and circumference. The area (A) of a circle with radius (r) is given by the formula:

Area of Circle (A) = π * (radius (r))^2

where π (pi) is a mathematical constant approximately equal to 3.14159.

The circumference (C) of a circle with radius (r) is calculated using the formula:

Circumference of Circle (C) = 2 * π * radius (r)

Implementing the Calculations in C

Now, let’s write the C program to perform the geometric calculations:

#include <stdio.h>

int main() {
    // Declare variables for rectangle and circle calculations
    float length, breadth, radius;
    float rectangleArea, rectanglePerimeter;
    float circleArea, circleCircumference;
    const float pi = 3.14159;

    // Input dimensions from the keyboard
    printf("Enter the length of the rectangle: ");
    scanf("%f", &length);

    printf("Enter the breadth of the rectangle: ");
    scanf("%f", &breadth);

    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);

    // Calculate rectangle area and perimeter
    rectangleArea = length * breadth;
    rectanglePerimeter = 2 * (length + breadth);

    // Calculate circle area and circumference
    circleArea = pi * radius * radius;
    circleCircumference = 2 * pi * radius;

    // Output the results
    printf("\nRectangle Area: %.2f\n", rectangleArea);
    printf("Rectangle Perimeter: %.2f\n", rectanglePerimeter);
    printf("Circle Area: %.2f\n", circleArea);
    printf("Circle Circumference: %.2f\n", circleCircumference);

    return 0;
}

Explanation

  1. We begin by including the necessary header file for input/output operations (stdio.h).
  2. Next, we declare variables to store the length, breadth, and radius entered through the keyboard. We also declare variables to store the calculated rectangle area, rectangle perimeter, circle area, and circle circumference.
  3. The user is prompted to input the length, breadth, and radius using the scanf() function.
  4. The program then calculates the rectangle area and perimeter using the given formulas.
  5. Similarly, the circle area and circumference are calculated using the provided formulas and the constant value of π (pi).
  6. The results are displayed on the screen with two decimal places using the printf() function.

Conclusion

By using this C program, you can effortlessly calculate the area and perimeter of a rectangle, as well as the area and circumference of a circle. These geometric calculations are valuable in various practical scenarios, from architectural planning to engineering design. Having the ability to input dimensions and obtain accurate results in seconds enhances productivity and problem-solving capabilities. So, next time you need to perform geometric calculations, rely on this simple C program to get the job done efficiently!

Leave a Comment