首页 > 试题广场 >

下面的程序有什么错误? #include in

[问答题]
下面的程序有什么错误?
#include <stdio.h>
int main (int argc, char argv[ ])
{
printf ("The square root of %f is %f\n", argv[1],
sqrt (argv[1]));
}

推荐
argv参数应该被声明为char *argv[]。命令行参数被存储为字符串,所以程序应该首先把argv[1]中的字符串转换为类型为double的值,例如,可以使用stdio.h库中的atof( )函数。应该为sqrt( )函数包含math.h头文件。程序在求平方根之前应进行检查参数是否为负值。
发表于 2018-03-26 21:19:55 回复(1)