2 solutions

  • 2
    @ 2023-10-22 15:05:16
    #include <stdio.h>
    #include <math.h>
    int main()
    {//用float设x,结果会有零点几的误差
    	double x1,x2,x3,y1,y2,y3,a=0,b=0,c=0,sum=0,i=0;
    	scanf("%lf %lf %lf %lf %lf %lf",
    	&x1,&y1,&x2,&y2,&x3,&y3);
    	a=sqrt(pow(x2-x1,2)+pow(y2-y1,2));
    	b=sqrt(pow(x3-x1,2)+pow(y3-y1,2));
        c=sqrt(pow(x2-x3,2)+pow(y2-y3,2));
        i=(a+b+c)/2.0;
    	sum=sqrt(i*(i-a)*(i-b)*(i-c));
    	printf("%.2f",sum);
    	return 0;
    }
    
    • @ 2024-10-2 9:43:16

      学长,为什么float 会有误差呢?

Information

ID
6726
Time
1000ms
Memory
128MiB
Difficulty
8
Tags
(None)
# Submissions
512
Accepted
82
Uploaded By