Write a C Program to enter length and breadth of a rectangle and find its perimeter - Basic C program



 

Write a C Program to enter length and breadth of a rectangle and find its perimeter .


Objective:

Write a C program to input length and width of a rectangle and calculate perimeter of the rectangle. How to find perimeter of a rectangle in C programming. Logic to find the perimeter of a rectangle if length and width are given in C programming.


Example


Input
Enter length: 5
Enter width: 10


Output

Perimeter of rectangle = 30 units

Perimeter of rectangle is given by the below formula

 Perimeter = 2 * (length + width).


Perimeter of rectangle


Where l is length and w is the width of rectangle.

Logic to find perimeter of a rectangle

Below is the step by step descriptive logic to find perimeter of a rectangle

Input length and width of the rectangle using scanf() function. Store it in two variables say length and width.
Calculate perimeter using formula for perimeter of rectangle perimeter = 2 * (length + width).
Print the value of perimeter.



Solution Code:

//C program to find perimeter of rectangle by CodexRitik #include <stdio.h> int main() { float length, width, perimeter; //Input length and width of rectangle from user printf("Enter length of the rectangle: "); scanf("%f", &length); printf("Enter width of the rectangle: "); scanf("%f", &width); /* Calculate perimeter of rectangle */ perimeter = 2 * (length + width); /* Print perimeter of rectangle */ printf("Perimeter of rectangle = %f units ", perimeter); return 0; }



Note:

This Code is Verified by CodexRitik.If any error occurs then Comment correct code Below in comment box.

Disclaimer:-

The above hole problem solution is generated by the CodexRitik . if any of the query regarding this post or website fill the following contact form Thank You.

Write a C Program to enter length and breadth of a rectangle and find its perimeter - Basic C program Write a C Program to enter length and breadth of a rectangle and find its perimeter - Basic C program Reviewed by CodexRitik on January 03, 2021 Rating: 5

No comments:

Powered by Blogger.