题目链接:http://bailian.openjudge.cn/practice/1005
# include <stdio.h>
# include <math.h>
const double PI=3.1415927; // const限定一个变量不允许被改变
int main()
{
int n,i=1;
int year;
double x,y;
double radius,area; //radius半径范围,area面积
scanf("%d",&n);
while(n--)
{
scanf("%lf%lf",&x,&y);
radius = x * x + y * y;
area = PI * radius / 2.0;
year = (int)ceil(area /50.0); // (int),把浮点型转换成整型,ceil函数上取整
printf("Property %d: ",i++); // property拥有权
printf("This property will begin eroding in year %d.\n",year);
}
printf("END OF OUTPUT.\n");
return 0;
}
本文通过C++编程实例,详细阐述了如何利用几何公式计算特定形状的面积,并结合浮点数运算和整数四舍五入,预测特定年份开始侵蚀的面积变化。代码实现了从输入坐标到输出预测年份的全过程,展示了将数学概念转化为实际应用的编程技巧。
309

被折叠的 条评论
为什么被折叠?



