How to calculate surface area of a triangle

By | June 16, 2019

Today, we will learn how to calculate surface area of a triangle. We will use the formula for surface area:

area = 1 /2  x base x height

Therefore, we must have base and height of the given triangle. We will prompt the user to input base and height of given triangle. Then we will use the above mentioned formula to calculate area of the given triangle easily.

how to calculate surface area of a triangle

how to calculate surface area of a triangle

Basic Statements Used in this Program

The basic statements used to write this C language program are as follows:

  1. Pre processor directives to include header files stdio.h for input / output operations.
  2. Writing main() function
  3. variable declaration statements
  4. printf() function for displaying messages
  5. scanf() function for input
  6. Use assignment statement for calculating simple formula to calculate area of triangle

Source Code for C Program how to calculate surface area of a triangle

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
/*
 C Program 
how to calculate surface area of a triangle
*/

#include<stdio.h>

int main()
{
   float area, base, height;
   printf("Enter base of triangle =");
   scanf("%f", &base);
   printf("Enter height of triangle =");
   scanf("%f", &height);
   area = 1.0 / 2.0 * base * height;
   printf("Area of Triangle =%f", area);
   return 0;
}

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *