接下来我们编写一个程序,求一个长方体的蓄水池可以用圆柱体的水桶多少桶注满。要求输入长方体蓄水池的长、宽、高和水桶的高、底部半径,输出所需水桶的数量,用#ifdet指令控制调试信息的显示和隐藏。
时间: 2024-03-30 12:36:30 浏览: 82
#ifdef DEBUG
#include <stdio.h>
#endif
#define PI 3.1415926
//#define DEBUG
int main() {
double length, width, height, bucketHeight, bucketRadius;
double poolVolume, bucketVolume;
int bucketNum;
printf("Please enter the length, width, and height of the pool: ");
scanf("%lf %lf %lf", &length, &width, &height);
printf("Please enter the height and bottom radius of the bucket: ");
scanf("%lf %lf", &bucketHeight, &bucketRadius);
#ifdef DEBUG
printf("length = %lf, width = %lf, height = %lf\n", length, width, height);
printf("bucketHeight = %lf, bucketRadius = %lf\n", bucketHeight, bucketRadius);
#endif
poolVolume = length * width * height;
bucketVolume = PI * bucketRadius * bucketRadius * bucketHeight;
#ifdef DEBUG
printf("poolVolume = %lf, bucketVolume = %lf\n", poolVolume, bucketVolume);
#endif
bucketNum = (int)(poolVolume / bucketVolume);
printf("It takes %d buckets to fill the pool.\n", bucketNum);
return 0;
}
阅读全文