Last Updated on April 25, 2023 by Prepbytes

The area of a rectangle program in C is a fundamental example of how to perform basic arithmetic operations and input/output operations in programming.

## What is Rectangle?

A rectangle is a four-sided flat shape where opposite sides of equal length and four right angles. The rectangle area is calculated as the total amount of space it occupies and may be estimated by multiplying its length by its breadth.

## How to the Find Area of Rectangle Program in C?

The area of rectangle program in C is a simple program that calculates by using the length and width input by the user. The program prompts the user to enter the length and width, reads those values and calculates the area, and outputs the result on the console

**The formula of area of rectangle program in C**

`area = length x width.`

### Algorithm for Area of Rectangle Program in C

The algorithm for the area of rectangle program in c:

- First, we declare two variables to store the length and width of the rectangle.
- Allow the user to enter the length and width of the rectangle.
- Now, read the length and width values entered by the user from the console.
- In this step, we calculate the area of the rectangle by multiplying the length and width values.
- Print the calculated area of the rectangle as an output.

### Example Code for Area of Rectangle Program in C

#include <stdio.h> int main() { float length, width, area; printf("Enter the length of the rectangle: "); scanf("%f", &length); printf("Enter the width of the rectangle: "); scanf("%f", &width); area = length * width; printf("The area of the rectangle is: %f\n", area); return 0; }

**Explanation for area of rectangle program in C:**

The above C program takes user input for the length and width of a rectangle, calculates the area using the formula "area = length x width", and then outputs the result. It utilizes the printf and scanf functions to display prompts and read in user input, respectively. Finally, the calculated area is printed to the console using printf.

**Conclusion**

In conclusion, the area of rectangle program in c explains how to use variables, user input, and basic mathematical operations are used. The program initiates the user to input the length and width of a rectangle, calculates the area using the formula "area = length x width", and then outputs the result. With a solid understanding of this program, you can build upon your C programming skills to attack more complex applications.

## Frequently Asked Questions(FAQs)

**Q1. What is the formula to calculate the area of a rectangle?**

**Ans:** The formula to calculate the area of a rectangle is area = length x width.

**Q2. What data type is used to store the length, width, and area of a rectangle in C?**

**Ans:** The float data type is used to store the length, width, and area of a rectangle in C.

**Q3. What are the functions used in the program to prompt the user to input values and display the calculated area?**

**Ans:** The printf function is used to display prompts for user input and prints it as output, and the scanf function is used to read in user input.

**Q4. What is the purpose of the return statement at the end of the program?**

**Ans:** The return statement at the end of the program describes that the program has been executed successfully and can be terminated. In C programming, a return value of 0 indicates that the program has been completed without any errors.

**Q5. How can this program be modified to calculate the perimeter of a rectangle?**

**Ans:** To calculate the perimeter of a rectangle, we need to use the formula perimeter = 2 x (length + width) instead of the formula for area. We also need to modify the printf statement for our output of the calculated perimeter instead of the calculated area.