本文主要是介绍4 最简单的 C 程序设计—顺序程序设计-4.6 顺序结构程序设计举例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
【例 4.14】输入三角形的三边长,求三角形面积。
#include <stdio.h>
#include <math.h> // 包含数学函数头文件main()
{/* 【例 4.14】输入三角形的三边长,求三角形面积。已知三角形的三边长 a,b,c,则该三角形的面积公式为: */float a, b, c, s, area;scanf("% f, % f, % f", &a, &b, &c);s = 1.0 / 2 * (a + b + c);area = sqrt(s * (s - a) * (s - b) * (s - c));printf("a = % 7.2f, b = % 7.2f, c = % 7.2f, s = % 7.2f\n", a, b, c, s);printf("area = % 7.2f\n", area);return 0;
}
#include <stdio.h>
#include <math.h> // 包含数学函数头文件main()
{float a, b, c, disc, x1, x2, p, q;scanf("a = % f, b = % f, c = % f", &a, &b, &c);disc = b * b - 4 * a * c;p = -b / (2 * a);q = sqrt(disc) / (2 * a);x1 = p + q;x2 = p - q;printf("\nx1 = % 5.2f\nx2 = % 5.2f\n", x1, x2);return 0;
}
这篇关于4 最简单的 C 程序设计—顺序程序设计-4.6 顺序结构程序设计举例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!