C program to find area of a rectangle
Write a C program to input length and width of a rectangle and find area of the given rectangle. How to calculate area of a rectangle whose length and breadth are given by user in C programming.
Input length= 2
Input width = 3
Area of rectangle = 6 sq. units
Required knowledge:
Fundamentals of C, Data types, Talking user input in C, Area of rectangleArea of rectanlge
Area of a rectangle is given by: length * widthProgram:
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 area of rectangle * ***************************************** */ #include <stdio.h>
void
main() { float length, width, area; /* Read length and width of rectangle from user * / printf ( "Enter length of rectangle: " ); scanf ( "%f" , &length); printf ( "Enter width of rectangle: " ); scanf ( "%d" , &width); /* Calculates area of rectangle */ area = length * width; /* Prints the area of rectangle */ printf ( "\nArea of rectangle = %f sq. units " , area); } |
Output
Enter length of rectangle: 5
Enter width of rectangle: 10
Area of rectangle = 50.000000 sq. units
Enter width of rectangle: 10
Area of rectangle = 50.000000 sq. units
Enjoy it..........................
Comments
Post a Comment
Dears! Yours Comment approved in 24 hours also your answer in 24 hours.......