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= 5
Input width = 10
Area of rectangle = 50 sq. units

Required knowledge:

Fundamentals of C, Data types, Talking user input in C, Area of rectangle

Area of rectanlge

Area of a rectangle can be given by: length * width

Program:

/**
 * C program to find area of rectangle
 */

#include <stdio.h>

int 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);

    return 0;
} 


Output
X
_
Enter length of rectangle: 5
Enter width of rectangle: 10

Area of rectangle = 50.000000 sq. units

Happy coding ;)


Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).

1 comment: