C程序来查找通过隧道的体积量
假设有一个高度为41且宽度非常大的隧道。我们还有一个包含长度、宽度和高度的盒子列表。如果盒子的高度恰好小于隧道高度,则它可以通过隧道。我们必须找到通过隧道的体积量。体积是长*宽*高。所以我们有一个数字N,一个N行三列的二维数组。
所以,如果输入像N=4个盒子=[[9,5,20],[3,7,15],[8,15,41],[6,3,42]],那么输出将是900和315我们可以通过前两个盒子,体积是9*5*20=900和3*7*15=315。不支持其他盒子的高度。
示例
让我们看看以下实现以获得更好的理解-
#include <stdio.h>
#define N 4
struct Box{
int length, width, height;
};
int volume(struct Box box){
return box.length*box.width*box.height;
}
int lower(struct Box box){
returnbox.height< 41;
}
int solve(struct Box boxes[]){
for (int i = 0; i < N; i++)
if (lower(boxes[i]))
printf("%d\n", volume(boxes[i]));
}
int main(){
struct Box boxes[N] = {{9,5,20},{3,7,15},{8,15,41},{6,3,42}};
solve(boxes);
}输入
4, {{9,5,20},{3,7,15},{8,15,41},{6,3,42}}输出结果900 315