搜索
查看: 671|回复: 4
打印 上一主题 下一主题

求一个计算三角形面积的程序代码

[复制链接]
跳转到指定楼层
楼主
发表于 2014-9-8 13:51:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
5啊哈币

沙发
发表于 2014-9-8 13:51:52 | 只看该作者
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>

  4. int main()
  5. {
  6.         int mode = 0;
  7.         double a = 0, b = 0, c = 0;
  8.         double h = 0;
  9.         int ch;

  10.         puts("Please select the mode:");
  11.         puts("1. The lengths of base and height are known");
  12.         puts("2. Lengths of all edges are know");

  13.         while(mode != 1 && mode != 2){
  14.                 if(scanf("%d", &mode) != 1)
  15.                         while((ch = getchar()) && ch != '\n')
  16.                                 ;
  17.         }

  18.         if(mode == 1){
  19.                 puts("Please input the lengths pf base and height");
  20.                 scanf("%lf %lf", &a, &h);
  21.                 if(a > 0 && h > 0)
  22.                         printf("S = %f\n", a * h / 2);
  23.                 else
  24.                         puts("input error");
  25.         }
  26.         else{
  27.                 puts("please input the lengths of all edges");
  28.                 scanf("%lf %lf %lf", &a, &b, &c);
  29.                 if(a > 0 && b > 0 && c > 0
  30.                         && a + b > c && b + c > a && a + c > b){
  31.                         double p = (a + b + c) / 2;
  32.                         double s = sqrt(p * (p - a) * (p - b) * (p - c));
  33.                         printf("S = %f\n", s);
  34.                 }
  35.                 else
  36.                         puts("input error");
  37.         }
  38.         system("pause");
  39.         return 0;
  40. }
复制代码
板凳
发表于 2014-9-8 15:04:58 | 只看该作者
。。。。。。。。。。。看不懂
地板
发表于 2014-9-11 17:01:22 | 只看该作者

这些你手打的嘛。需要多久啊
5#
发表于 2014-9-11 19:17:53 | 只看该作者
今个没吃药 发表于 2014-9-11 17:01
这些你手打的嘛。需要多久啊

现写的所以是手打的,大概要十几分钟
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表