// 求面积.cpp :定义控制台应用程序的入口点.
#include "stdafx.h"
#include
#include
//
double square(float num1[5],float num2[5])
{
double side[7],length[3],squ[3];
int i;
for(i=0;i<4;i++) /*两点之间的线段长*/
side[i]=sqrt((num1[i+1]-num1[i])*(num1[i+1]-num1[i])+(num2[i+1]-num2[i])*(num2[i+1]-num2[i]));
side[5]=sqrt((num1[2]-num1[0])*(num1[2]-num1[0])+(num2[2]-num2[0])*(num2[2]-num2[0]));
side[6]=sqrt((num1[4]-num1[2])*(num1[4]-num1[2])+(num2[4]-num2[2])*(num2[4]-num2[2]));
side[4]=sqrt((num1[4]-num1[0])*(num1[4]-num1[0])+(num2[4]-num2[0])*(num2[4]-num2[0]));
length[0]=(side[0]+side[1]+side[5])*1.0/2;
squ[0]=sqrt(length[0]*(length[0]-side[0])*(length[0]-side[1])*(length[0]-side[5])); /*求三角形的面积*/
length[1]=(side[2]+side[3]+side[6])*1.0/2;
squ[1]=sqrt(length[1]*(length[1]-side[2])*(length[1]-side[3])*(length[1]-side[6]));
length[2]=(side[4]+side[5]+side[6])*1.0/2;
squ[2]=sqrt(length[2]*(length[2]-side[4])*(length[2]-side[5])*(length[2]-side[6]));
return (squ[0]+squ[1]+squ[2]); /*返回三角形的面积之和*/
}
int _tmain(int argc,_TCHAR* argv[])
{
float num1[5]=,num2[5]=;
double square1=0,squ[3]=;
int i;
printf("please input the points in turnn");
for(i=0;i<5;i++)
{
scanf("%f%f",&num1[i],&num2[i]);
printf("%f%fn",num1[i],num2[i]);
}
square1=square(num1,num2); /*五边形面积等于三个三角形面积之和*/
printf("%f",square1);
return 0;
}