C语言计算矩形体积和表面积
#include <stdio.h>
int main() {
float l, w, h;
printf('请输入矩形的长、宽、高(用空格隔开):');
scanf('%f %f %f', &l, &w, &h);
float volume = l * w * h;
float area1 = l * w;
float area2 = w * h;
float area3 = l * h;
printf('体积为:%.2f\n', volume);
printf('三个面的面积分别为:\n');
printf('%.2f\n', area1);
printf('%.2f\n', area2);
printf('%.2f\n', area3);
return 0;
}
注意:这里使用了 float 类型,因为长度、宽度、高度可能是带小数的。%.2f 表示保留两位小数。
原文地址: https://www.cveoy.top/t/topic/ocjs 著作权归作者所有。请勿转载和采集!