EduSeekho | Knowledge Milega, Success Dikhega!

C Program to Find Area and Perimeter of Rectangle

Find Area And Perimeter of Rectangle Using C Program
Table of Contents

C Program to Find Area and Perimeter of Rectangle is a fundamental exercise in understanding basic programming concepts and arithmetic operations. This simple yet practical program allows you to input the dimensions of rectangle, calculate its area using the formula Length × Breadth, and determine the perimeter with 2 × (Length + Breadth). Whether you’re new to programming or looking to brush up on your skills, this program provides a clear and straightforward way to apply logic, handle user inputs, and display results, making it an essential task for any beginner in C programming.

Introduction

The first basic things to learn in the process of learning C programming concern how to work with geometrical figures, like the rectangle. Calculation of area and perimeter of rectangle is among the simplest but important exercises, reinforcing concepts such as handling input, arithmetic operations, and formatting output in C.

Whether you are designing a lawn, building a room, or just working through a programming exercise, knowing how to compute these values is sensible and essential. In this blog, we’re going to stroll you through the steps of making a C program to find area and perimeter of rectangle, helping you understand the underlying standards in a clear and simple manner.

About Rectangle

Learn what a rectangle is, and the way to calculate its area and perimeter using easy formulas.

What is a Rectangle?

A rectangle is a four-sided shape where opposite sides are equal in length, and each of its four angles is a right angle (90 degrees). Rectangles are everywhere around us, from books and screens to doors and tables. Because of their simple and regular shape, rectangles are easy to measure and work with in various applications.

Area of Rectangle
Area of Rectangle

Area of a Rectangle

The quantity of space that a rectangle occupies on a surface that is flat is referred to as its area. Think about how big a rectangle­ is. This is its area. It’s like having a rectangular pie­ce of paper. The space­ that paper takes up, that’s its area. To calculate the area, you multiply the length of the rectangle by its breadth (width). The formula for the area is:

Area = Length × Breadth

For example, if a rectangle has a length of five units and a breadth of three units, the area might be 5×3 which is 15 square units.

Perimeter of Rectangle
Perimeter of Rectangle

Perimeter of a Rectangle

Think of a rectangle’s perimeter as a path that goes all the way around it. Imagine needing a rope to wrap around a rectangular box. You find this perimeter, or this ‘rope length’, by adding all four sides of the rectangle together. Or, you can just use a predefined, easy formula:

Perimeter = 2 × (Length + Breadth)

Let us take an example where a rectangle has length five units and width three units. Its perimeter is 2×(5+3) = 16 units.

Properties of Rectangle

Get to know a rectangle’s main features. Think about its angles, sides, and symmetry. These are the geome­tric characteristics that make it so special.

  1. Four Sides: A rectangle has four sides.
  2. Opposite Sides are Equal: The length of the opposite sides is equal.
  3. Four Right Angles: All four corners of a rectangle shape right angles, which might be 90 degrees each.
  4. Diagonals are Equal: The two diagonals of a rectangle are equal in length.
  5. Symmetry: A rectangle is symmetric about both its diagonals and its central axes

Understanding the fundamental properties of a rectangle is crucial for solving problems that are associated with geometry and programming puzzles.

C Program To Find Area And Perimeter of Rectangle
C Program To Find Area And Perimeter of Rectangle

C Program to Find Area and Perimeter of Rectangle

So, let’s de­vise a basic C program. This program will invite the use­r to enter the dime­nsions of a rectangle- both length and width. Afte­r that, it will work out the area and perime­ter and show these to the­ user.

#include <stdio.h>

int main() {
    float length, width, area, perimeter;

    // Asking the user for the length and width of the rectangle
    printf("Enter the length of the rectangle: ");
    scanf("%f", &length);

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

    // Calculating area
    area = length * width;

    // Calculating perimeter
    perimeter = 2 * (length + width);

    // Displaying the results
    printf("Area of the rectangle: %.2f\n", area);
    printf("Perimeter of the rectangle: %.2f\n", perimeter);

    return 0;
}

Example Output

Here’s what the output might look like if you run the program:

Enter the length of the rectangle: 5
Enter the width of the rectangle: 3
Area of the rectangle: 15.00
Perimeter of the rectangle: 16.00

This program is a great way to practice basic C programming concepts like input, output, and simple arithmetic operations.

Steps to Create C Program to Find Area and Perimeter of Rectangle

Let’s dive into making a C program. This helpful code will find a rectangle’s area and perimeter. It’s an easy task to build your programming basics. We’ll walk you through each step, from starting your code to running it and showing the outcome. You’ll grasp how this all works by sticking to these clear steps. You’ll also feel more sure about writing programs like­ this later on. Here we go!

  1. Open Your Text Editor: Start by opening your preferred text editor or IDE (e.g., Code::Blocks, Visual Studio Code, etc.).
  2. Create a New File: Create a new file and name it rectangle_area_perimeter.c.
  3. Include the Necessary Library: At the top of your file, include the stdio.h library using the #include <stdio.h> statement.
  4. Declare the Main Function: Write the int main() function to start the program.
  5. Declare Variables: Inside the main function, declare variables to store the length, width, area, and perimeter.
  6. Input Length and Width: Use printf to prompt the user for the length and width of the rectangle, and scanf to read the values.
  7. Calculate Area and Perimeter: Perform the necessary calculations for the area and perimeter.
  8. Display the Results: Use printf to output the calculated area and perimeter to the user.
  9. End the Program: Conclude the main function with return 0;.
  10. Save and Compile: Save your file and compile it using a C compiler.
  11. Run the Program: Run the compiled program and enter the values when prompted to see the results.
Flowchart for C Program to Find Area and Perimeter of Rectangle
Flowchart for C Program to Find Area and Perimeter of Rectangle

Flowchart of C Program to Find Area and Perimeter of Rectangle

A flowchart is a graphic approach to illustrate the processes of a program. It facilitates comprehension of the program’s logic prior to composing the source code. The next part will provide a straightforward flowchart illustrating the process of developing a C program for calculating the area and perimeter of a rectangle. By adhering to the flowchart, one can readily see the operational mechanisms of the program, starting with the acquisition of input to the presentation of the outcomes. Examine the flowchart and analyze each individual step.

C Program To Find Area of Rectangle
C Program To Find Area of Rectangle

C Program to Find Area of Rectangle

To calculate the region of ​​a rectangle using C programming, you must input the duration and width of the rectangle. The application will then use the components Area = Length × Breadth to calculate the area using these values. This is a easy however effective exercising to help novices understand how to manage input and output in C, in addition to how to carry out basic mathematics operations.

Here’s the C code to find area of a rectangle:

#include <stdio.h>

int main() {
    float length, breadth, area;

    // Prompt the user to enter the length and breadth of the rectangle
    printf("Enter the length of the rectangle: ");
    scanf("%f", &length);

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

    // Calculate the area using the formula: Area = Length × Breadth
    area = length * breadth;

    // Display the calculated area
    printf("The area of the rectangle is: %.2f\n", area);

    return 0;
}

Example Output

Here’s an example of how the program might work when you run it:

Enter the length of the rectangle: 6
Enter the width of the rectangle: 5
Area of the rectangle: 30.00

In this example, the user entered 5.5 for the length and 3.2 for the width. The program then calculated the area as 17.60 square units and displayed it to the user. The output is formatted to two decimal places for clarity.

C Program To Find Perimeter of Rectangle
C Program To Find Perimeter of Rectangle

C Program to Find Perimeter of Rectangle

In this phase, we will look at the way to write a C application to calculate the fringe of a rectangle. The perimeter is the whole distance around the rectangle, and the formulation to calculate it is:

Perimeter = 2 × (Length + Breadth)

By using this formula in a C program, you can quickly find perimeter by inputting the length and breadth of the rectangle. Here’s how you can write the code:

#include <stdio.h>

int main() {
    float length, breadth, perimeter;

    // Asking user to input the length and breadth of the rectangle
    printf("Enter the length of the rectangle: ");
    scanf("%f", &length);

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

    // Calculating the perimeter
    perimeter = 2 * (length + breadth);

    // Displaying the result
    printf("The perimeter of the rectangle is: %.2f\n", perimeter);

    return 0;
}

Example Output

Here’s what the output of the program might look like when you run it:

Enter the length of the rectangle: 6
Enter the width of the rectangle: 5
Area of the rectangle: 30.00

In this example:

  • The user entered 5.5 as the length and 3.2 as the breadth.
  • The program then calculated the perimeter as 17.40 units and displayed the result.

Conclusion on C Program to Find Area and Perimeter of Rectangle

In this blog, we’ve included a way to write a C program to find area and perimeter of rectangle, step by step. By know-how the code, the flowchart, and the overall technique, you’ve gained insights into a way to carry out basic mathematics operations and deal with user inputs in C.

Whether you’re new to programming or trying to sharpen your abilties, getting to know these fundamentals is important. With this knowledge, you’re now geared up to address comparable issues and follow these techniques to a number of programming demanding situations. Keep experimenting and building on what you’ve learned to beautify your coding information!

FAQs on C Program to Find Area and Perimeter of Rectangle

Here are some common questions which is FAQs and answers about creating c program to find area and perimeter of rectangle.

The purpose of this C program is to calculate two fundamental properties of a rectangle based on user input: the area, which is the space contained within the rectangle, and the perimeter, which is the total length around the rectangle. This helps in various applications, such as designing layouts or understanding spatial dimensions.

The program uses the scanf function to receive input from the user. It prompts the user to enter the length and width of the rectangle, which are then stored in the variables provided for further calculations.

The program accepts floating-point values for length and width, allowing for both whole numbers and decimals. This flexibility accommodates various measurements, such as centimeters or meters, depending on the context.

The float data type is used because it can store decimal numbers, which is important for accurately representing measurements that are not whole numbers. This ensures precision in calculations involving real-world dimensions.

The area is calculated by multiplying the length and width (area = length * width), while the perimeter is calculated by adding the length and width and then multiplying by 2 (perimeter = 2 * (length + width)). These formulas are based on the geometric properties of a rectangle.

Still unsure about C Program to Find Area and Perimeter of Rectangle? Find more programs under C Programs & If you want to compile and test the c programs, use Online C Compiler

Share The Post: C Program to Find Area and Perimeter of Rectangle On

C Program to Find Area and Perimeter of Rectangle Article By EduSeekho