请看一下这个程序有什么问题?


/* POW.C
 *
 */
#include<stdio.h>
double power(double x, double y);
void main(void)

{
    double x = 2.0, y = 3.0, z;
    z = power(x, y);
    printf("%.1f to the power of %.1f\n", x, y, z);
}
double power(double x, double y)
{
    double z=1;
    while (y)
    {
        z *= x;
        --y;
    }
    return z;
}

printf("%.1f to the power of %.1f is %.1f\n", x, y, z);
z参数输出还少一个是少一个%f。
Exited with error status 28 的报错的话是因为缺少主函数。
将void main 改为 int即可。

没有什么大问题呀!运行起来有警告而已。

#include <stdio.h>
#include <stdlib.h>

double power(double x, double y);

int main()
{
    double x = 2.0, y = 3.0, z;
    z = power(x, y);
    printf("%.1f to the power of %.1f is %.1f\n", x, y, z);
    return 0;
}

double power(double x, double y)
{
    double z=1;
    while (y)
    {
        z *= x;
        --y;
    }
    return z;
}

刚才查了一下资料,c标准里规定main返回值必须为int,虽然能运行,但是会有警告。