计算概论(A)/基础编程练习2(8题)/3:计算三角形面积
#include<stdio.h>
#include<math.h>
int main() {
// 声明三角形的三个顶点坐标和面积
float x1, y1, x2, y2, x3, y3, s; // 输入坐标
scanf("%f %f %f %f %f %f",&x1, &y1, &x2, &y2, &x3, &y3); // 利用欧氏距离计算边长
float a, b, c;
a=sqrt(1.0*(x2-x1)*(x2-x1)+1.0*(y2-y1)*(y2-y1));
b=sqrt(1.0*(x1-x3)*(x1-x3)+1.0*(y1-y3)*(y1-y3));
c=sqrt(1.0*(x3-x2)*(x3-x2)+1.0*(y3-y2)*(y3-y2)); // 利用海伦公式计算三角形面积
float p=(a+b+c)/2.0;
s=sqrt(1.0*p*(p-a)*(p-b)*(p-c)); printf("%.2f\n", s);
return ;
}
/*
pkuic_6172.c
计算概论(A)/基础编程练习2(8题)/3:计算三角形面积
http://pkuic.openjudge.cn/base2/3/
3:计算三角形面积
查看 提交 统计 提问
总时间限制: 1000ms 内存限制: 65536kB
描述
平面上有一个三角形,它的三个顶点坐标分别为(x1, y1), (x2, y2), (x3, y3),那么请问这个三角形的面积是多少。
输入
输入仅一行,包括6个单精度浮点数,分别对应x1, y1, x2, y2, x3, y3。
输出
输出也是一行,输出三角形的面积,精确到小数点后两位。
样例输入
0 0 4 0 0 3
样例输出
6.00
提示
海伦公式
*/
计算概论(A)/基础编程练习2(8题)/3:计算三角形面积的更多相关文章
- 计算概论(A)/基础编程练习2(8题)/2:计算书费
#include<stdio.h> int main() { // 声明与初始化 ; // k组测试数据的总费用 double s[k]; // 单价表 double price[]= { ...
- 计算概论(A)/基础编程练习2(8题)/8:1的个数
#include<stdio.h> int main() { ; // 存储测试数据的二进制形式中1的个数 int bian[N]; // 输入十进制整数N 表示N行测试数据 scanf( ...
- 计算概论(A)/基础编程练习2(8题)/7:整数的个数
#include<stdio.h> int main() { ] = {}; // 输入k个正整数 scanf("%d",&k); // 循环读入和进行算术 w ...
- 计算概论(A)/基础编程练习2(8题)/6:数组逆序重放
#include<stdio.h> int main() { // 输入n个整数 ; scanf("%d", &n); // 循环读入元素 while(scan ...
- 计算概论(A)/基础编程练习2(8题)/5:点和正方形的关系
#include<stdio.h> #include<math.h> int main() { // 输入坐标 float x, y; while(scanf("%f ...
- 计算概论(A)/基础编程练习1(8题)/2:苹果和虫子
#include<stdio.h> #include<math.h> int main() { /* n个苹果 每x小时能吃掉一个苹果 经过y小时 */ float n, x, ...
- 计算概论(A)/基础编程练习1(8题)/1:大象喝水
#include<stdio.h> int main() { ; // n < 100 scanf("%d", &n); // 循环遍历判断 再进行平方和 ...
- 计算概论(A)/基础编程练习2(8题)/4:骑车与走路
#include<stdio.h> int main() { // 待处理的数据数量n ; scanf("%d", &n); float meters[n]; ...
- 计算概论(A)/基础编程练习2(8题)/1:求平均年龄
#include<stdio.h> int main() { // 声明与初始化 , s=, age=; // 输入学生人数 scanf("%d", &n); ...
随机推荐
- python模块路径
Python会在以下路径中搜索它想要寻找的模块: 1. 程序所在的文件夹 2. 标准库的安装路径 3. 操作系统环境变量PYTHONPATH所包含的路径 将自定义库的路径添加到Python的库路径中去 ...
- poj 2125 Destroying The Graph 最小割+方案输出
构图思路: 1.将所有顶点v拆成两个点, v1,v2 2.源点S与v1连边,容量为 W- 3.v2与汇点连边,容量为 W+ 4.对图中原边( a, b ), 连边 (a1,b2),容量为正无穷大 则该 ...
- js备忘录_2
JS函数的参数在function内可以用arguments对象来获取. 转化为数组:var arr=Array.prototype.slice.call(arguments,0); Array有两个: ...
- java.exe和javaw.exe有什么区别
- PAT甲1005 Spell it right【字符串】
1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all th ...
- opengl学习笔记(一)
ubuntu下opengl的安装及配置 OpenGL 是一套由SGI公司发展出来的绘图函数库,它是一组 C 语言的函数,用于 2D 与 3D 图形应用程序的开发上.OpenGL 让程序开发人员不需要考 ...
- js 基础 函数传值
让我忽略的函数传值问题 function box(num){ num += 10; // num(有色的num) 实际就是arguments[0] ,如果参数没有num,则函数体的num(有色的nu ...
- This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in
地址:http://stackoverflow.com/questions/18852983/eclipse-reports-rendering-library-more-recent-than-ad ...
- Cache replacement policies 缓存实现算法
Cache replacement policies - Wikipedia https://en.wikipedia.org/wiki/Cache_replacement_policies Cach ...
- Dubbo简单环境搭建
Dubbo服务的发展和作用: 首先,看下一般网站架构随着业务的发展,逻辑越来越复杂,数据量越来越大,交互越来越多之后的常规方案演进历程. 其次,当服务越来越多之后,我们需要做哪些服务治理? 最后,是d ...