C program to find perimeter of a rectangle
Write a C program to input length and width of a rectangle from user and calculate perimeter of the rectangle. How to find perimeter of a rectangle if length and breadth of a rectangle are given using C programming.
Input length: 5
Input Width: 5
Perimeter of rectangle = 20 units
Required knowledge:
Fundamentals of C, Data types, Taking user input in C, Perimeter of rectanglePerimeter of rectangle:
Perimeter of a rectangle can be expressed using below formula:
Where l is the length and w is the width of rectangle.
Program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| /** * C program to find perimeter of a rectangle */#include <stdio.h>void main(){ float length, width, perimeter; /* * Reads 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); /* Calculates perimeter of rectangle */ perimeter = 2 * (length + width); /* Prints perimeter of rectangle */ printf("\nPerimeter of rectangle = %f units ", perimeter);} |
Output
Enter length of the rectangle: 5
Enter width of the rectangle: 5
Perimeter of rectangle = 20.000000
Enter width of the rectangle: 5
Perimeter of rectangle = 20.000000
Enjoy it...............
Comments
Post a Comment
Dears! Yours Comment approved in 24 hours also your answer in 24 hours.......