Google面试题 07042012 [1]

本文介绍了一个C++函数,该函数接收三个整数作为输入,分别代表三角形三边的长度,并返回一个整数值来确定三角形的类型:不等边三角形、等腰三角形、等边三角形或错误情况。此外,还提供了主函数用于输入三角形的边长并输出其类型。
/*
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;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值