【发布时间】:2015-02-17 04:16:25
【问题描述】:
您如何制作如图所示的表格(您使用的是理想气体定律)。音量值应该从最左边的列开始,开始音量并以相等的步长增加 这样最右边一列的成交量就是停止成交量。对于表中的每个条目,计算给定温度和体积下的压力,请帮助。
成交量:10.00 --- 18.89 --- 27.78 --- 36.67
温度:
300.00 - 24.94 --- 13.20 --- 8.98 --- 6.80
400.00 - 33.26 --- 17.61 ---11.97--- 9.07
500.00 - 41.57 --- 22.01 ---14.97--- 11.34
#include <stdio.h>
int main(void)
{
float vol1, vol2;
float temp1, temp2;
float R = 8.314;
int mole;
int rows;
int columns = 8;
printf("Enter the starting volume (in meters cubed):");
scanf("%f",&vol1);
while(vol1<0)
{
printf("Error: Enter a number that is positive:");
scanf("%f",&vol1);
}
printf("Enter the ending volume (in meters cubed):");
scanf("%f",&vol2);
while(vol2<0)
{
printf("Error: Enter a number that is positive:");
scanf("%f",&vol2);
}
printf("Next enter the starting temperature (in kelvin):");
scanf("%f",&temp1);
while(temp1<0)
{
printf("Error: Enter a number that is positive:");
scanf("%f",&temp1);
}
printf("Enter the ending temperature (in kelvin):");
scanf("%f",&temp2);
while(temp2<0)
{
printf("Error: Enter a number that is positive:");
scanf("%f",&temp2);
}
printf("Enter the number of moles:");
scanf("%f",&mole);
while(mole<0)
{
printf("Error: Enter a number that is positive:");
scanf("%f",&mole);
}
printf("How many rows should the temperature value have?\n");
scanf("%d",&rows);
while(rows<1)
{
printf("Error: Enter a number that is positive:");
scanf("%d",&rows);
}
return 0;
}
【问题讨论】:
-
你的问题不是很清楚。提供更多细节,您希望我们做什么(我无法理解您的表格)。
-
为什么提示输入值而不是让用户将它们作为参数传递?这是一个非常不自然的界面。
标签: c loops for-loop while-loop