In this tutorial, i am going to show you how to find or calculate area of equilateral Triangle with the help of standard formula, function and pointer in c programs.
All C Programs and Algorithm to Find Area of Equilateral Triangle
- Algorithm to Find Area of a Equilateral Triangle
- C Program to Find Area of a Equilateral Triangle using sqrt
- C Program to Find Area of a Equilateral Triangle using Function
- C Program to Find Area of a Equilateral Triangle using Pointer
Algorithm to Find Area of a Equilateral Triangle
Follow the below given algorithm to write a program to find the area of a equilateral Triangle; as follows:
- Take input side of triangle. Store it in variable.
- Calculate area of an Equilateral triangle using
(sqrt 3)/4 * a^2
- Finally, print the value of Area of an Equilateral triangle.
C Program to Find Area of a Equilateral Triangle using sqrt
#include<math.h> int main() { float area,a; printf("enter side of the triangle: "); scanf("%f",&a); area=(sqrt(3)/4)*a*a; printf("AOET:%f\n",area); return 0; }
The result of the above c program; as follows:
enter side of the triangle: 5 AOET:10.825317
C Program to Find Area of a Equilateral Triangle using Function
#include<stdio.h> #include<math.h> float area(float a) { float Ar=(sqrt(3)/4)*a*a; return Ar; } int main() { float Ar,a; printf("enter side of the triangle: "); scanf("%f",&a); Ar=area(a); printf("AOET: %f\n",Ar); return 0; }
The result of the above c program; as follows:
enter side of the triangle: 7 AOET: 21.217623
C Program to Find Area of a Equilateral Triangle using Pointer
#include<stdio.h> #include<math.h> float area(float *a,float *Ar) { *Ar=(sqrt(3)/4)* (*a) * (*a); } int main() { float a,Ar; printf("enter side: "); scanf("%f",&a); area(&a,&Ar); printf("AOET: %f\n",Ar); return 0; }
The result of the above c program; as follows:
enter side: 6 AOET: 15.588457