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.
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
A = length of side code-box
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.
#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; }
Area of Rectangle
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.
#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; }
Area of Triangle
B = Base H = Vertical Height code-box
In this program, We put the Hero formula of the area of a triangle. Here it is...
#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; }
Area of Circule
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; }
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