/*
Write a function that receives three integer inputs for the lengths of the sides of a triangle and returns one of four values to determine the triangle type (1=scalene, 2=isosceles, 3=equilateral, 4=error). Generate test cases for the function assuming another developer coded the function
*/
#include <iostream>
int getTriangleType(int a, int b, int c)
{
if(a < 0 || b < 0 || c < 0 || a + b < c || a + c < b || b + c < a)
return 4;
else if(a == b && b == c)
return 3;
else if(a == b || b == c || a == c)
return 2;
else
return 1;
};
int main()
{
int a, b, c;
std::cout << "a = ";
std::cin >> a;
std::cout << std::endl;
std::cout << "b = ";
std::cin >> b;
std::cout << std::endl;
std::cout << "c = ";
std::cin >> c;
std::cout << std::endl;
std::cout << "Type: " << getTriangleType(a, b, c);
return 0;
}Google面试题 07042012 [1]
最新推荐文章于 2025-12-17 16:35:43 发布
本文介绍了一个C++函数,该函数接收三个整数作为输入,分别代表三角形三边的长度,并返回一个整数值来确定三角形的类型:不等边三角形、等腰三角形、等边三角形或错误情况。此外,还提供了主函数用于输入三角形的边长并输出其类型。
16万+

被折叠的 条评论
为什么被折叠?



