'Calculate three angle of triangle using three sides
I want to find three angle of a Triangle using Given three sides but it gives me 'nan' value.
I have tried law of cosines to find the angles but it ain't working. It gives 'nan' value.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
using namespace std;
double findDegree(double setDegree)
{
return setDegree * M_PI / 180;
}
double findRadian(double setRadian)
{
return acos(setRadian);
}
int main()
{
cout << endl;
cout << "Give three sides of the triangle: ";
int a, b, c;
cin >> a >> b >> c;
double angleA, angleB, angleC, getRadian, getDegree;
angleA = ((b * b) + (c * c) - (a * a)) / 2 * b * c;
angleB = ((a * a) + (c * c) - (b * b)) / 2 * a * c;
angleC = ((a * a) + (b * b) - (c * c)) / 2 * a * b;
// A
getRadian = findRadian(angleA);
getDegree = findDegree(getRadian);
angleA = getDegree;
// B
getRadian = findRadian(angleB);
getDegree = findDegree(getRadian);
angleB = getDegree;
// A
getRadian = findRadian(angleC);
getDegree = findDegree(getRadian);
angleC = getDegree;
cout << "Angle A is: " << angleA << endl;
cout << "Angle B is: " << angleB << endl;
cout << "Angle C is: " << angleC << endl;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
