推荐阅读置顶帖(望新手借鉴),这样会好点
代码代码,带着的石头码!!!
#include <stdio.h> #include <math.h> bool foo( int x1, int y1, int x2, int y2, int x3, int y3, double* c, double* s ) { if( (x2-x1)*(y3-y1) == (x3-x1)*(y2-y1) ) return false; *c = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+0.0) + sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2)+0.0) + sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)+0.0); *s = 0.5 * fabs( (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1)+0.0 ); return true; } int main( void ) { double c, s; if( !foo(0,0, 1,3, 3,2, &c,&s) ) printf( "%s\n", "Impossible" ); else printf( "L = %.2f, A = %.2f\n", c, s ); if( !foo(0,0, 1,1, 2,2, &c,&s) ) printf( "%s\n", "Impossible" ); else printf( "L = %.2f, A = %.2f\n", c, s ); return 0; }