> 【问题描述】从键盘输入三角形的三个边,判断是否构成三角形,若能,则输出该三角形的面积及类型(等腰,等边,直角,等腰直角,一般),否则输出“can not form a triangle”
提示:用海伦公式求解三角形面积s=sqrt(p*(p-a)(p-b)(p-c));p=(a+b+c)/2.0;sqrt为开方函数,需在头文件里添加#include<math.h>
使用方法示例:a的开方 sqrt(a)
【输入形式】输入3个整数 【输出形式】输出第一行为三角型种类,第二行为面积
等腰:This is an isosceles triangle.
等边:This is an equilateral triangle.
直角:This is a right triangle.
一般:This is a general triangle.
不是三角:can not form a triangle.
如果是等边和直角,不再需要输出等腰。
【样例输入】1 1 1 【样例输出】This is an equilateral triangle.
The area of this triangle is 0.43.
#include <stdio.h>
#include <math.h>
int main() {
int a, b, c;
float p, s;
scanf("%d %d %d", &a, &b, &c);
p = (a + b + c) / 2.0;
s = sqrt(p * (p - a) * (p - b) * (p - c));
if (a == b && b == c && a == c) {
printf("This is an equilateral triangle.\n");
printf("The area of this triangle is %.2f.", s);
return 0;
}
if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a) {
printf("This is a right triangle.\n");
printf("The area of this triangle is %.2f.", s);
return 0;
}
if (a == b || a == c || b == c) {
printf("This is an isosceles triangle.\n");
printf("The area of this triangle is %.2f.", s);
} else if (a + b <= c || a + c <= b || b + c <= a) {
printf("can not form a triangle.\n");
} else {
printf("This is a general triangle.\n");
printf("The area of this triangle is %.2f.", s);
}
return 0;
}
> 【问题描述】
一个最简单的计算器,支持+, -, *, / 四种运算。仅需考虑输入输出为整数的情况(除法结果就是商,忽略余数)
【输入形式】
输入只有一行,共有三个参数,其中第1、2个参数为整数,第3个参数为操作符(+,-,*,/)。
【输出形式】
输出只有一行,一个整数,为运算结果。然而:
【样例输入】
+ 1 2
【样例输出】
3