In this tutorial you will learn about the C Program to Find Area of a Rectangle using Length and Width and its application with practical example.
C Program to Find Area of a Rectangle using Length and Width
In this tutorial, we will learn to create a C program that will Find the Area of a Rectangle using Length and Width in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Arithmetic operations in C programming.
What is a rectangle?
The rectangle is four sides geometrical shape with pair of two sides parallel and of the same size as each other. The Rectangle has the length and the width in it.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input length and the width of the <strong>Rectangle </strong>from the user. 3. <strong>C</strong><strong>alculating the Area of a Rectangle </strong>using the arithmetic expression length * width. 4. Printing the area of the <strong>Rectangle</strong>. 5. End the program. |
Program description:-
In this tutorial, we will create a program, that will find the Area of the Rectangle. we will First, take the length and the width of the Rectangle from the user. Then we will calculate the area of the Rectangle using arithmetic expressions / the formulae for the area of the Rectangle. At last, we will print the Area of the Rectangle.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
//C Program to Find Area of a Rectangle using Length and Width #include<stdio.h>//including the header file for the program int main()//body of the main function { //declaring the required variables for the prorgam. float recwth, reclgth, recar; //recwth = it will hold the value for width of Rectangle. //reclgth = it will hold the value for length of Rectangle. //Taking the input height of the Rectangle printf ("\n Please Enter the Width of a Rectangle : "); scanf ("%f",&recwth); //Taking the input lenght of the Rectangle. printf ("\n Please Enter the Length of a Rectangle : "); scanf ("%f",&reclgth); //calculating the area of a Rectangle recar = reclgth * recwth; //printing the Area of the Rectangle printf("\n The Area of a Rectangle = %.2f", recar); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- recwth = it will hold the input value for the base of the Rectangle.
- reclgth = it will hold the input value for the height of the Rectangle.
- recar= it will hold the value of the area of the Rectangle.
Taking the input width and the length of the Rectangle.
Calculating the area of the Rectangle.
Printing the area of the Rectangle.