C Program to Find Area of Rectangle

In this program, we will learn how to find the area of a rectangle using C Programming language.

This program asks the user to enter the length and breadth of the rectangle. Then, it computes and prints the area of the rectangle.

So, without further ado, let’s begin this tutorial.

C Program to Find Area of Rectangle

// C Program to Find Area of Rectangle
#include <stdio.h>
int main(){
    int length, breadth, area;
    
    // Asking for input
    printf("Enter the length of the rectangle: ");
    scanf("%d", &length);
    printf("Enter the breadth of the rectangle: ");
    scanf("%d", &breadth);
    
    // Calculating Area
    area = length * breadth;
    
    // Displaying the output
    printf("Area of the Rectangle: %d", area);
    return 0;
}

Output

Enter the length of the rectangle: 5
Enter the breadth of the rectangle: 7
Area of the Rectangle: 35

How Does This Program Work ?

    int length, breadth, area;

In this program, we have declared some int data type variables which will store the dimensions of the rectangle.

    // Asking for input
    printf("Enter the length of the rectangle: ");
    scanf("%d", &length);
    printf("Enter the breadth of the rectangle: ");
    scanf("%d", &breadth);

Then, the user is asked to enter the length and breadth of the rectangle.

    // Calculating Area
    area = length * breadth;

Now, we calculate the area using the mathematical formula:

Area = Length x Breadth

    // Displaying the output
    printf("Area of the Rectangle: %d", area);

Finally, the result is displayed on the screen using printf() function.

Conclusion

I hope after going through this post, you understand how to find the area of a rectangle using C Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.

Also Read:

2 thoughts on “C Program to Find Area of Rectangle”

  1. Imtiyaz Ahmed

    If we write the area calculation part just before the input of user it is not working. I was just wanted to know why it is? Replying will be appreciated 😊

    1. It’s because when you write the area code earlier, at that time length and breadth variables doesn’t contain any values. Hence, the area calculated is invalid. If you want to write area code earlier, then you have to create a custom function to perform the task.

      Thank you

Leave a Comment

Your email address will not be published.