C Program to Find Area of Rectangle

Howdy readers, today you will learn how to write a program to find the area of a rectangle using the C Programming language.

C Program to Find Area of Rectangle

The area of a rectangle (A) is the product of its length ‘a’ and breadth ‘b’.

  • Area of Rectangle (A) = Length (a) x Breadth (b)

The below program prompts the user to enter the length and breadth of a rectangle, then it computes the area using the above formula.

So, without any delay, let’s begin this tutorial.

C Program to Find Area of Rectangle

C Program

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

Output

Enter the length of rectangle: 5.4
Enter the breadth of rectangle: 7.6
Area of the rectangle is: 41.04
C Program to Find Area of Rectangle

Explanation

    float length, breadth, area;

We have declared three float data type variables named length, breadth and area.

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

Then, the program prompts the user to enter the length and breadth.

    // Calculating the area
    area = length * breadth;

Area of the rectangle is computed using the formula, area = length x breadth.

    // Displaying result
    printf("Area of the rectangle is: %.2f", area);

Finally, the area of the rectangle is displayed on the screen using printf() function. The %.2f format specifier is used to limit the result to 2 decimal places.

Conclusion

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

If you have any queries regarding the program, then let us know in the comment section. We will be pleased to solve all of your queries.

Leave a Comment