Solution to the Triangle problem in C++