I think i need a houseboot C语言 UVA2363

使用题给数据计算出面积,然后向上取整,若向下取整会提前1年失去土地。

然后使用一个for循环得到失去土地的时间

 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.\n",i+1,j);
20         }
21         printf("END OF OUTPUT.");
22     }
23     return 0;
24 }
View Code

 

posted @ 2018-07-29 21:53  小小的嘤嘤怪  阅读(163)  评论(0编辑  收藏  举报
TOP