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. 


Example: 
Input length= 2
Input width = 3 
Area of rectangle = 6 sq. units

Required knowledge:

Fundamentals of CData typesTalking user input in CArea of rectangle 

Area of rectanlge

Area of a rectangle is given by: length * width 

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 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
X
_
Enter length of rectangle: 5
Enter width of rectangle: 10

Area of rectangle = 50.000000 sq. units

Enjoy it..........................

Comments

Popular posts from this blog

C program to calculate velocity

C program to find square root of a number

C program to find maximum between two numbers