㈠ C语言 CFF1115.找数 小程序求查错
#include<stdio.h>
#include<math.h>
intmain(void)
{
回doublea,b,c,disc,x1,x2,p,q;
scanf("%lf%lf%lf",&a,&b,&c);
disc=b*b-4*a*c;
if(disc<0)
答printf("Thisequationhasn'trealroots! ");
else
{
p=-b/(2.0*a);
q=sqrt(disc)/(2.0*a);
x1=p+q;x2=p-q;
printf("realroots: x1=%7.2f x2=%7.2f ",x1,x2);
}
return0;
}
㈡ 杭电ACM1115为啥WA求解释
这么做看看.
#include<stdio.h>#include<stdlib.h>int main(){ double x0,y0,x1,y1,x2,y2; int n,m; scanf( "%d",&n ); for( int i=1; i<=n; i++ ) { double sx=0,sy=0,s=0; scanf( "%d",&m ); scanf( "%lf%lf%lf%lf",&x0,&y0,&x1,&y1 ); for( int j=2;j<m; j++ ) { scanf("%lf%lf",&x2,&y2); double S=0.5*( ( x1-x0 )*( y2-y0 )-( x2-x0 )*( y1-y0 ) ); sx+=S*( x0+x1+x2 ); sy+=S*( y0+y1+y2 ); s+=S; x1=x2; y1=y2; } printf( "%.2lf %.2lf\n",sx/( 3*s ),sy/( 3*s ) ); } return 0; }