前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >作业-2

作业-2

作者头像
小屁的博客
发布2024-02-02 20:22:45
690
发布2024-02-02 20:22:45
举报
文章被收录于专栏:小屁折腾日记小屁折腾日记

> 【问题描述】从键盘输入三角形的三个边,判断是否构成三角形,若能,则输出该三角形的面积及类型(等腰,等边,直角,等腰直角,一般),否则输出“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.

代码语言:javascript
复制
#include &lt;stdio.h&gt;
#include &lt;math.h&gt;

int main() {
    int a, b, c;
    float p, s;
    scanf(&quot;%d %d %d&quot;, &amp;a, &amp;b, &amp;c);
    p = (a + b + c) / 2.0;
    s = sqrt(p * (p - a) * (p - b) * (p - c));
    if (a == b &amp;&amp; b == c &amp;&amp; a == c) {
        printf(&quot;This is an equilateral triangle.\n&quot;);
        printf(&quot;The area of this triangle is %.2f.&quot;, s);
        return 0;
    }
    if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a) {
        printf(&quot;This is a right triangle.\n&quot;);
        printf(&quot;The area of this triangle is %.2f.&quot;, s);
        return 0;
    }
    if (a == b || a == c || b == c) {
        printf(&quot;This is an isosceles triangle.\n&quot;);
        printf(&quot;The area of this triangle is %.2f.&quot;, s);
    } else if (a + b &lt;= c || a + c &lt;= b || b + c &lt;= a) {
        printf(&quot;can not form a triangle.\n&quot;);
    } else {
        printf(&quot;This is a general triangle.\n&quot;);
        printf(&quot;The area of this triangle is %.2f.&quot;, s);
    }
    return 0;
}

> 【问题描述】

一个最简单的计算器,支持+, -, *, / 四种运算。仅需考虑输入输出为整数的情况(除法结果就是商,忽略余数)

【输入形式】

输入只有一行,共有三个参数,其中第1、2个参数为整数,第3个参数为操作符(+,-,*,/)。

【输出形式】

输出只有一行,一个整数,为运算结果。然而:

  1. 如果出现除数为0的情况,则输出:Divided by zero!
  2. 如果出现无效的操作符(即不为 +, -, *, / 之一),则输出:Invalid operator!

【样例输入】

代码语言:javascript
复制
+ 1 2

【样例输出】

代码语言:javascript
复制
3
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-09-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档