In this tutorial you will learn about the C Program to Find Area of a Triangle using Base and Height and its application with practical example.
C Program to Find Area of a Triangle using Base and Height
In this tutorial, we will learn to create a C program that will Find the Area of a Triangle using Base and Height in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Arithmetic Operations in C programing.
What is a triangle?
In geometry, a triangle is a shape used to be drawn by the three lines. The triangle has three interior angles and the total of its interior angle is 180 degrees.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input height and width of the triangle. 3. Calculating the of <strong>area </strong>triangle using the code. 4. Printing the area of a triangle. 5. End the program. |
Program description that will print the area of a Triangle:-
In this tutorial, we will create a program, that will find the area of a triangle using C programming. First, take the input height and the width of the triangle by the user. Then we will calculate the area of that triangle using the mathematical expression. At last, we will print the area of a triangle.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* C Program to find Area Of a Triangle using base and height */ #include<stdio.h> int main() { //declaring the required variables for the program float bs, ht, area; //Taking the input base from the user printf("\n Please Enter the base of a Triangle : "); scanf("%f", &bs); //Taking the input height from the user printf("\n Please Enter the height of a Triangle : "); scanf("%f", &ht); //Calculating the area of the triangle area = (bs * ht) / 2; //Printing the area of the triangle printf("\n The Area of a Triangle using base and height = %.2f\n", area); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- bs = it will hold the value for the input base of the triangle.
- ht = it will hold the value for the input height of the triangle.
- area = it will hold the integer value for the area of a triangle.
Input the base and height of the triangle.
Code to calculate the area of the triangle.
Printing output the area of an isosceles triangle.