BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to calculate Area of an Equilateral triangle

By Chaitanya Singh | Filed Under: C Programs

In this tutorial, you will learn how to write a C program to calculate area of An equilateral triangle. A triangle is called equilateral triangle if all three of its sides are equal.

Formula to calculate area of an equilateral triangle:

Area = (sqrt(3)/4 )* (side * side)

Program to calculate Area of an Equilateral triangle

In this program, user is asked to enter the side of the triangle. All sides of this triangle are equal and we just need to use this value in the above formula to calculate the area.

Here we will also need to include the math.h header file as we are using the function sqrt() which is predefined in the math.h header file.

The steps followed in this program are:
1. Prompt user to input the side of the triangle. Store this entered value in variable side. We need this variable in next steps to calculate area.
2. Use the the above mentioned formula to calculate area based on the input value of side. = (sqrt(3) / 4) * (side * side).
3. Print the area of equilateral triangle as the output.

#include <stdio.h>
#include <math.h> //to use sqrt() function
int main()
{
  // Variable area to store calculated area, "temp"
  // variable to store the result of temporary calculation
  // and side represents the side of the triangle
  float side, area, temp;

  // Prompt user to input side of the Equilateral triangle
  printf("Enter the Side of the triangle: ");
  scanf("%f",&side);

  //Calculate and print the area of Equilateral Triangle
  temp = sqrt(3) / 4 ;
  area = temp * side * side ;
  printf("Area of Equilateral Triangle is: %f",area);

  return 0;
}

Output:
C Program to calculate Area of an Equilateral triangle

Related C Examples:

  • C Program to calculate power of a number
  • C Program to calculate and print the value of nPr
  • C Program to calculate area and circumference of circle
  • C Program to find LCM of two numbers
❮ C TutorialC Programs ❯

Leave a Reply Cancel reply

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

Programs

  • C Programs
  • Java Programs
  • C++ Programs

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap