新手请教,请求改正程序错误!
新手请教,请求改正程序错误!
初次接触Visual C++ 6.0,以下是考试例题,但编译出错,请帮忙修改!
已知e? 1? 1/1!? 1/2!? 1/n!? 试用上述公式求e的近似值.
要求累加所有不小于10^-6的项值,部分程序给出如下,请完成该程序,实现上述功能.
程序版本:Visual C++ 6.0
程序代码如下:
#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[])
{ int i;
float e,n;
e=1.0;i=1;
n=1.0;
for(;n>=1e-6;i++)
{n=1.0/Fun(i);
e+=n;}
printf("%f\n",e);
return 0;
}
Fun(int i)
{ int j,k;
k=1;
for (j= 1; j<=i; ++j)
k = k*j;
return k;
}
以下是编译出错信息!
--------------------Configuration: chapter5 - Win32 Debug--------------------
Compiling...
chapter5.cpp
E:\xuexi\vc++\example\chapter5\chapter5.cpp(13) : error C2065: 'Fun' : undeclared identifier
E:\xuexi\vc++\example\chapter5\chapter5.cpp(13) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
E:\xuexi\vc++\example\chapter5\chapter5.cpp(20) : error C2373: 'Fun' : redefinition; different type modifiers
执行 cl.exe 时出错.
chapter5.exe - 1 error(s), 0 warning(s)