首页 > 试题广场 >

Dottie Cawm写的下面这个程序中有很多错误,找出这些

[问答题]
Dottie Cawm写的下面这个程序中有很多错误,找出这些错误。
include<stdio.h>
main
(
float g; h;
float tax, rate;
g = e21
tax = rate*g;
)

推荐
第1行:应该是#include<stdio.h>。
第2行:应该是int main (void).
第3行:使用{,而不是(。
第4行:在g和h之间应该是逗号而不是分号。
第5行:无错误。
第6行:(空行)无错误。
第7行:在e之前应该至少有一个数字,1e21或1.0e21都是正确的,尽管这个数有点大。
第8行:无错误,至少在语法上没有。
第9行:使用}而不是)。
缺少的行:首先,rate没有被赋值。其次,变量h从来没有被使用。而且程序永远不会把它的计算结果通知给您。这些错误都不会阻止程序的运行(尽管可能会向您出示一个警告以说明变量没有被使用),但是它们确实减弱了程序本来就不多的功能。而且在结尾处应该有一个return语句。
下面是正确版本之一:
#include<stdio.h>
int main(void)
{
float g,h;
float tax,rate;
rate = 0.08;
g = 1.0e5;
tax = rate*g;
h = g + tax;
printf("You owe $%f in taxes for a total of $%f.\n",g,tax,h);
return 0;
}

发表于 2018-05-05 22:14:20 回复(0)
#include<stdio.h>
int main()
{
    float g,h;
    float tax, rate;
    g = 1e21;
    tax = rate*g;
    h = tax;
    return 0;
}

编辑于 2020-02-10 11:56:31 回复(0)