使用题给数据计算出面积,然后向上取整,若向下取整会提前1年失去土地。
然后使用一个for循环得到失去土地的时间
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 5 int main(void){ 6 int n,i,j; 7 int s; 8 double pi=3.1415926; 9 double *x,*y; 10 double r; 11 while(scanf("%d",&n)==1){ 12 x=(double *)malloc(n*sizeof(double)); 13 y=(double *)malloc(n*sizeof(double)); 14 for(i=0;i<n;i++) scanf("%lf %lf",&x[i],&y[i]); 15 for(i=0;i<n;i++){ 16 r=sqrt(x[i]*x[i]+y[i]*y[i]); 17 s=(int)(pi*r*r/2); 18 for(j=1;s>j*50;j++); 19 printf("Property %d: This property will begin eroding in year %d. ",i+1,j); 20 } 21 printf("END OF OUTPUT."); 22 } 23 return 0; 24 }