Definition:
A rectangle is a four-sided shape with opposite sides equal. The area of a rectangle is calculated by multiplying its width by its length.
Formula:
Area = Width × Length
Explanation:
This program accepts the width and length of a rectangle from the user using the scanf() function. Both values are stored as float data type, and the area is calculated using the formula Area = Width × Length.
Explanation: This program accepts the width and length of a rectangle and calculates its area.
#include <stdio.h> #include <conio.h> main() { float a,w,l; clrscr(); printf("Enter Width of Rectangle : "); scanf("%f",&w); printf("Enter Length of Rectangle : "); scanf("%f",&l); a = w * l; printf("\nArea of Rectangle = %.2f",a); getch(); }
Output:
Explanation: This program accepts the side of a square and calculates its area using the formula Side × Side.
#include <stdio.h> #include <conio.h> main() { float side,area; clrscr(); printf("Enter Side of Square : "); scanf("%f",&side); area = side * side; printf("\nArea of Square = %.2f",area); getch(); }
Output:
Explanation: This program accepts the base and height of a triangle and calculates its area using the formula (Base × Height) / 2.
#include <stdio.h> #include <conio.h> main() { float base,height,area; clrscr(); printf("Enter Base : "); scanf("%f",&base); printf("Enter Height : "); scanf("%f",&height); area = (base * height) / 2; printf("\nArea of Triangle = %.2f",area); getch(); }
Output:
float data type and scanf() function to calculate the area of a rectangle.Area = Width × Length.#include <stdio.h> #include <conio.h> main() { float base,height,area; clrscr(); printf("Enter Base : "); scanf("%f",&base); printf("Enter Height : "); scanf("%f",&height); area = (base * height) / 2; printf("\nArea of Triangle = %.2f",area); getch(); }
Area = Width × Length, and displays the result.
float data type.Area = Side × Side.#include <stdio.h> #include <conio.h> main() { float side, area; clrscr(); printf("Enter Side : "); scanf("%f",&side); area = side * side; printf("\nArea of Square = %.2f", area); getch(); }
Area = Side × Side, and displays the result.
float data type.Area = (Base × Height) / 2.#include <stdio.h> #include <conio.h> main() { float base, height, area; clrscr(); printf("Enter Base : "); scanf("%f",&base); printf("Enter Height : "); scanf("%f",&height); area = (base * height) / 2; printf("\nArea of Triangle = %.2f", area); getch(); }
Area = (Base × Height) / 2, and displays the result.