在VS中运行以下程序,在除法部分结果出错了,请各位大神指导下,谢谢。
#include
#include
#include
#define DENSITY 62.4
int main(void)
{double weight,volume;
int size,letters;
char name[45];
printf("Hi!What's your first name?\n");
scanf("%s",name);
printf("%s,what's your weight in pounds?\n",name);
scanf("%f",&weight);
size=sizeof name;
letters=strlen(name);
volume=weight/DENSITY;
printf("Well,%s,your volumn is %2.2f cubic feet.\n",name,volume);
printf("Also,your first name has %d letters,\n",letters);
printf("and we have %d bytes to store it.\n",size);
system("pause");
return 0;
}
结果
volumn的结果是-14833270029408700000000000000000000000000
但在VC中运行结果为2.72,这是正确的。