【发布时间】:2014-10-15 12:01:51
【问题描述】:
我只有一个简短的问题。我将如何在每个 if 语句行中引入乘法,以便将 Height * Width * Depth 一起计时以获得体积。我希望为每一行都这样做。我已经插入了我的代码副本,只是想真正添加。
{
int Height;
int Width;
int Depth;
scanf("%d%d%d", &Height, &Width, &Depth );
if(Height == Width && Depth >=0){
printf("It's a square cuboid\nThe volume is %d ");
}
if(Height == Depth && Width >= 0)
printf("It's a square cuboid\n ");
if(Width == Depth && Height >= 0)
printf("It's a square cuboid\n");
if(Height == Width && Height == Depth)
printf("It's a perfect cube\n ");
}
【问题讨论】:
-
不清楚你在问什么。如果你想要一个乘法,那么就写一个乘法;)
-
写
Height * Width * Depth -
另外,我希望输出显示在“音量为 %d”的位置,但我如何将 %d 与最终答案相关联?
-
@HadleighGaudreau,我已经在回答中解释过了
-
如果它是一个完美的立方体并且所有值都 >= 0,那么所有的 printf 语句都会被执行。
标签: c if-statement multiplication statements