C Program to Find Area of Circle and Area of Triangle

CodeForHunger
2 min readMay 21, 2024

In this post we are going to explore how to find area of circle and area of triangle using C language. Whether you are a beginner wanting to grasp a basic knowledge of programming or someone experienced needing a quick reminder, this guide will help you with easy steps and clear examples. By the end of this, you will know how to calculate these important areas using C. Let’s get started!

1. C Program to Find Area of Circle:

Input from user:

Enter the radius of the circle: 5

Expected Output:

Area of circle is: 78.500000

To find area of circle we need to use pi(π). Because pi(π) represents the ratio of the circumference of a circle to its diameter.

Step by step logic of the program:

1. First we need to declare two variable’s. One for accepting radius of the circle from user and second one is for store the area of circle.

2. So declare variable’s r for radius of the circle and a for area of the circle.

3. To find area use area of circle’s simple logic which π*r²(pi r square).

4. Here pi’s value is 3.14. so we will write a=3.14*r*r.(here r=5)

5. Last we will print value of a(area of circle) on the output screen.

Example:

#include<stdio.h>
int main()
{

int r;
float a;

printf("Enter radius of the circle:\n");
scanf("%d",&r);

a=3.14*r*r;

printf("Area of circle is %f",a);

return 0;
}

OUPUT:

Enter radius of the circle: 5

Area of circle is 78.500000

2. C Program to Find Area of Triangle:

Input from user:

Enter the breadth of triangle: 5

Enter the height of triangle: 10

Expected output:

Area of triangle: 25.0000

Step by step descriptive logic of the given program:

1. First accept breadth and height of the triangle from user.

2. Use variable b for breadth and h for height of the triangle and a for store area of triangle.

3. In the logic multiply breadth into height and devide it by 2 a=(b*h)/2.

4. Print a(area of triangle) on the output screen.

Example:

#include<stdio.h>
int main()
{

int b,h;
float a;

printf("Enter the breadth of triangle\n");
scanf("%d",&b);

printf("Enter the height of the triangle\n");
scanf("%d",&h);

a=(b*h)/2;

printf("Area of triangle is %f",a);

return 0;

}

OUTPUT:

Enter the breadth of triangle: 5

Enter the height of the triangle: 10

Area of triangle is : 25.000000

--

--

CodeForHunger

Here, I will share tips & tricks to learn programming languages, Learn C and Java with lot of exercises, coding examples & interview questions. Follow for more.