Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Monday, July 13, 2020

C program to find area and perimeter of equilateral triangle

C Program to find area and perimeter of equilateral triangle:
By Ahmad Irshad | Programming Exercises and Solutions > find area & perimeter of equilateral triangle.

Write a C program to find area and perimeter of equilateral triangle if it's sides are given. 

Before writing any program you just imagine about output screen first. Like what input to be given, and output to be displayed. Let's have a look at the below example.

  1. INPUT

  2. Enter side of an equilateral triangle = 15
  OUTPUT

Enter side of an equilateral triangle = 97.43 sq.units
Perimeter of an equilateral triangle = 43.3 units

Required knowledge for this exercise is

Area & perimeter of equilateral triangle if it's sides are given:

Area & perimeter of equilateral triangle | Protec
Use farmula to find perimeter of an equilateral triangle, P = 3 * Side 
Where S = Side, A = Area, and P = Peremeter.

Logic to find area and perimeter of equilateral triangle if sides are given:

Step by step logic to find area and perimetre of equilateral triangle.

1) Print a massage to the user like "Enter side of an equilateral triangle:" using printf();
2) Input side of an equilateral triangle from user and store it in a variable side using scanf();
3) Now find area and perimeter of equilateral triangle using below farmula
area = sqrt(3) / 4 (side * side); and perimeter = 3 * side;
4) At last print the value of area and perimeter. that's it!


Program to find area & perimeter of an equilateral triangle if sides are given: 

  1. /* C program to find area of equilateral triangle if it's sides are given */
  2. #include <stdio.h> #include <math.h> // Used for sqrt() function int main() { float side, area, perimeter; /* Input side of equilateral triangle from user */ printf("Enter side of an equilateral triangle: "); scanf("%f", &side); /* Calculate area & perimeter of an equilateral triangle */ area = (sqrt(3) / 4) * (side * side); perimeter = 3 * side
  3. /* Print the value of area & perimeter */ printf("Area of equilateral triangle = %.2f sq. units", area); printf("Perimeter of equilateral triangle = %.2f units", perimeter); return 0; }

%.2f is used to print real values only up to 2 decimal places. You can also use %f to print up to 6 decimal places by default.

sqrt() is a function which is used to find square root of a given number.

Output:

  1. Enter side  of an equilateral triangle = 15
  2. Area of equilateral triangle = 97.43 sq. units
  3. Perimeter of  equilateral triangle = 45 units

Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us