Today we are here to write a C Program to Calculate the Area and Perimeter Of Rectangle. In this program we’ll use the formula’s of area of rectangle and perimeter of rectangle. First we want to know that what is rectangle? Rectangle is a four sided quadrilateral. All their interior angles are of 90 degree and their opposite side must be equal. To find the area of rectangle we multiply it’s length and width.
What is Perimeter of Rectangle? Perimeter is the linear distance around the boundary of rectangle. To find the Perimeter of rectangle we use the formula of Perimeter of rectangle that is 2*(length + width).
C Program to Calculate the Area and Perimeter Of Rectangle:
First we have the header file that is standard input output(#include<stdio.h>). After the header file we are using main function. So what is main function? Main function is function in which printf and scanf functions are built in so that’s why main function is used. After that body of the main function starts and then the statements is written inside the body of the main function. The statements that are inside the body of main function will be executed to print the result and displays it on the screen.
To calculate the area of rectangle, we need it’s length and width. First we take the length and width from the user using scanf function and stores them in the variables “length” and “width“. First when we enter the values of length and width compiler gives us the area of rectangle. And by printf function we can print the result/area of rectangle area on the screen.
After execution of the printf statement it will find the perimeter of the rectangle and gives us the value of perimeter of the rectangle. And again by printf function compiler will give us the answer on the display screen. You can initialize the value in the program instead of using scan (scanf) function. But this is not the professional method/way to write a program. Initialization of a program would be studied on the basic level.
Perimeter of Rectangle:
But as your level up you have to use scanf (scan) function to take the value from the user. . This is the most common, best and easy method to take the value from the user. We can find the area of rectangle simply by multiplying it’s length and width. To find the perimeter of the rectangle we multiply 2 with the sum of length and width. This formula gives us the perimeter of the rectangle. So let’s start creating a C Program to Calculate the Area and Perimeter Of Rectangle. The program is given below the paragraph:
C Program to Calculate the Area and Perimeter Of Rectangle Example:
#include<stdio.h> int main() { int length,width,perimeter,area; printf("Enter the length and width of the rectangle\n"); scanf("%d %d",&length,&width); //Formula of Area Of Rectangle// //Calculate Area of Rectangle// area=length*width; //Printing Area Of Rectangle// printf("Area of rectangle=%d\n",area); //Formula of Perimeter Of Rectangle// //Calculating Perimeter of Rectangle// perimeter=2*(length+width); //Printing Perimeter Of the Rectangle// printf("Perimeter of rectangle=%d\n",perimeter); return 0; }
Output:
Conclusion:
In the above C Program to Calculate the Area and Perimeter Of Rectangle and the image shows us we take 9 as a length and 8 as width from the user and the program will gives us the area and perimeter of the rectangle that is equal to 72. From the above program we are now able to write a “C Program To Find The Area Of Rectangle and Perimeter Of Rectangle” simply by using their formula’s. So must try this program by your own.
[sc_fs_faq html=”true” headline=”h4″ img=”” question=” How do you find the perimeter and area of a rectangle in C?” img_alt=”” css_class=””] Sum of the length and width and multiplying its sum by 2. [/sc_fs_faq]
[sc_fs_faq html=”true” headline=”h4″ img=”” question=”How do you measure area of a rectangle?” img_alt=”” css_class=””] By multiplying its length and width simply [/sc_fs_faq]
YouTube Link: