beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

C Program to calculate Area of Equilatral triangle

By Chaitanya Singh | Filed Under: C Programs

An equilateral triangle has equal sides(all three sides are equal). In this tutorial, we have shared a C program, which takes triangle side as input and calculates & displays the area as output.

Program to calculate Area

In order to calculate the area of equilateral triangle, we must know the side of the triangle. This program would prompt user to enter the side of the equilateral triangle and based on the value, it would calculate the area.

Formula used in the program:
Area = sqrt(3)/4 * side * side
Here sqrt refers the “square root”, this is a predefined function of “math.h” header file. In order to use this function, we have included the “math.h” header file in the program.

#include<stdio.h>
#include<math.h>
int main()
{
   int triangle_side;
   float triangle_area, temp_variable;

   //Ask user to input the length of the side
   printf("\nEnter the Side of the triangle:");
   scanf("%d",&triangle_side);

   //Caluclate and display area of Equilateral Triangle
   temp_variable = sqrt(3) / 4 ;
   triangle_area = temp_variable * triangle_side * triangle_side ;
   printf("\nArea of Equilateral Triangle is: %f",triangle_area);
   return(0);
}

Output:

Enter the Side of the triangle: 2
Area of Equilateral Triangle is: 1.732051

Enjoyed this post? Try these related posts

  1. C Program to find largest element of an Array
  2. C Program to Convert Decimal to Octal Number
  3. C Program to find Palindrome numbers in a given range
  4. C Program to find prime numbers in a given range
  5. C Program to Multiply two Floating Point Numbers
  6. C Program to find greatest of three numbers

Leave a Reply Cancel reply

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

Programs

  • C Programs
  • Java Programs

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap