I'm making a program that reads each side of a triangle, calculates its degrees and determines whether it's a right triangle, a scalene triangle or not a triangle.
I'm calculating its cosine then find the degree from the cosine: the cos equation
Here's the code:
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int a,b,c;
double val, cA, cB, cC, angleA, angleB, angleC;
int main()
{
printf("Input the length of each side!");
printf("\na: ");
scanf("%d", &a);
printf("\nb: ");
scanf("%d", &b);
printf("\nc: ");
scanf("%d", &c);
//calculating the cosine
cA = ((b*b)+(c*c)-(a*a))/(2*b*c);
cB = ((a*a)+(c*c)-(b*b))/(2*a*c);
cC = ((a*a)+(b*b)-(c*c))/(2*a*b);
val = 180.0/PI;
if(cA>=0&&cA<=1){
angleA = acos(cA)*val;
} else{
angleA = 0;
}
if(cB>=0&&cB<=1){
angleB = acos(cB)*val;
} else{
angleB = 0;
}
if(cC>=0&&cC<=1){
angleC = acos(cC)*val;
} else{
angleC = 0;
}
printf("\ncos A= %lf", cA);
printf("\ncos B= %lf", cB);
printf("\ncos C= %lf", cC);
printf("\nAngle A= %lf", angleA);
printf("\nAngle B= %lf", angleB);
printf("\nAngle C= %lf", angleC);
}
I'm still trying to calculate the cosine, but the cA, cB, cC only gives zero whenever I input the side values of a triangle.
cos A= 0.000000
cos B= 0.000000
cos C= 0.000000
How to get the cos equation to return the correct value of the cosine?