C Program to find area of different shapes

 C Program to Find Area of Different Shapes

Here, you will learn to write a C Program to find the area of many Different types of Shapes.

Calculation The area is completely base on formulas. You can calculate the area of different shapes if you know the formula for that particular shape.

Let's start with understanding the logic then will see the C programs for the area.

C Program to find area for different shapes

What is AREA?

" The area is the size of a surface "

There were many formulas for calculating area for different shapes. 

Here, We share some popular formulas for the area With those C Program Codes.

Our first C Program is " Write the C program to find the area of square ".

Area of Square

Area of Square = A × A
 A = length of side code-box

First, We write basic codes which are the same for all C programs.

Then we carate input and output codes for getting the value from the user and display the result of a calculation.

Here, we use float because the value may be in floating-point.

[ Float Number is a Number with pointed values like 25.36 ]

In the middle of the program, we just put the formula of the area of a square. 

Let's see in the actual C program.

#include<stdio.h>
int main() {
    //Declaration of variable
    float value,answer;
    // Get valuse for numbers by user
    printf("\nEnter value [ Lenght of side ] = ");
    scanf("%f",&value);

    // Calculation of Area of Square
    answer=value*value;

    // Display Answer of Area of Square 
    printf("Answer of Square = %.2f",answer);

    // Direct display the answer without use other variable
   /* printf("Answer of Square = %.2f",value*value); */
    return 0; 
}
OUTPUT :
Enter value [ Lenght of side ] = 25
Answer of Square = 625 code-box

Area of Rectangle

Area of Rectangle = W × H
W = Width     H = Height code-box

In this program, we just change the formula of the area of a square to the area of a rectangle.

Let's, The C Program to find the area of a rectangle.

#include<stdio.h>
int main() {
    //Declaration of variable
    float width,hight,answer;
    // Get valuse for numbers by user
    printf("\nEnter value width = ");
    scanf("%f",&width);
    printf("\nEnter value hight = ");
    scanf("%f",&hight);

    // Calculation of Area of rectangle
    answer=width*hight;

    // Display Answer of Area of rectangle 
    printf("Answer of rectangle = %.2f",answer);

    // Direct display the answer without use other variable
   /* printf("Answer of rectangle = %.2f",width*hight); */
    return 0; 
}
OUTPUT :
Enter value width = 10
Enter value hight = 15
Answer of rectangle = 150 code-box

Area of Triangle

Area of Triangle = ½ × B × H
B = Base  H = Vertical Height code-box

In this program, We put the Hero formula of the area of a triangle. Here it is...

Let's, The C Program to find the area of a Triangle.

#include<stdio.h>
int main() {
    //Declaration of variable
    float base,vertical_hight,answer;
    // Get valuse for numbers by user
    printf("\nEnter value width = ");
    scanf("%f",&base);
    printf("\nEnter value hight = ");
    scanf("%f",&vertical_hight);

    // Calculation of Area of Triangle
    answer=0.5*base*vertical_hight;

    // Display Answer of Area of triangle 
    printf("Answer of Triangle = %.2f",answer);

    // Direct display the answer without use other variable
   /* printf("Answer of Triangle = %.2f",0.5*base*vertical_hight); */
    return 0; 
}
OUTPUT :
Enter value width = 5
Enter value hight = 12
Answer of Triangle = 30.00 code-box

Area of Circule

Area of Circle = π × R2
R = Radius code-box

At last, we see, The C Program to find the area of a Circle.

#include<stdio.h>
int main() {
    //Declaration of variable
    float radius,answer;
    // Get valuse for numbers by user
    printf("\nEnter value radius = ");
    scanf("%f",&radius);

    // Calculation of Area of Circle
    answer=3.14*radius*radius;

    // Display Answer of Area of Circle
    printf("Answer of Circle = %.2f",answer);

    // Direct display the answer without use other variable
   /* printf("Answer of Circle = %.2f",3.14*radius*radius); */
    return 0; 
}
OUTPUT :
Enter value radius = 2.6
Answer of Circle = 21.23 code-box

So those are some C programs for finding areas. Those all C programs are the same. We just changed the formulas as per shape.

Get the right formulas and you can write the C program for other mathematic calculations.

If you have any questions regarding the C Programming or Program code, then write in the comment box and we will solve them.

Post a Comment

Post a Comment (0)

Previous Post Next Post