C Language | Area of any Triangle

Wednesday 19 December 2012

Trigonometry is a study of triangles. In trigonometry, there are a lot of theorems, postulates and equations for specific triangles. There are also great mathematicians and philosophers who created formulas for specific topics.

During my first semester in a trigonometry class we were asked to make a program in C language out of the topics we discussed the whole semester. As for me, I made a program that calculates the area of a triangle given only three sides. This program was based on the theorem which Heron, a Greek philosopher and mathematician, created. This theorem is known as the SSS Theorem, made out from the Law of Cosines.

The program I made is basically filled with mathematical equations and statements. So, I included a header file that reads specific mathematical commands and that is math.h. To experience the program, check out the codes below.

#include<conio.h>
#include<stdio.h>
#include<math.h>



int main()
{  
 
    float a,b,c;
    float s,area;
 
    printf("Enter side a: ");
    scanf("%f",&a);
 
    printf("Enter side b: ");
    scanf("%f",&b);
 
    printf("Enter side c: ");
    scanf("%f",&c);
 
    s = (a+b+c)/2;
    area = sqrt(s*(s-a)*(s-b)*(s-c));
 
    printf("\nArea of triangle is: %.2f",area);
 
    getch();
}


The program runs like these. When executed, the program will ask the user to enter three inputs which will be the given sides of a triangle. Then the inputs will be stored on the three storage variables declared above namely a, b and c. These variables will go through the equations. As seen above, there are two equations present, the semi perimeter equation and the equation in finding the area. After executing the equations the program will now show you the result running the printf statement. Then you can now terminate the program. Check out the sample output below.



Hopefully this program helped you a lot. Hope to hear from you soon. Thanks!

C Language | Trigonometric Function SINE

Trigonometry is the study of any triangles. In this, trigonometric functions are present to help us calculate anything from missing areas to missing sides to elevations. There are six (6) Trigonometric Functions namely sine, cosine, tangent, cotangent, secant and cosecant.

In connection to trigonometric functions I made a program that shows you how it works. This program shows you how to calculate for the sine function equivalent of any triangle. This program is used with the header file math.h to allow mathematical commands inside the program. Check out the sample codes below.


     1: #include <stdio.h>
   2:  #include <conio.h>
   3:  #include <math.h>
   4:  # define pi 3.14159265
   5:   
   6:   
   7:  int main()
   8:  {
   9:            int angleA;
  10:            
  11:            printf ("Enter angle: ");
  12:            scanf("%d", &angleA);
Related Posts Plugin for WordPress, Blogger...