用C语言编写程序,求S=1+(1/2!)+(2/3!)+·····+(n/(n+1!)),直到最后一项的绝对值小于10^-5

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/24 19:48:04
用C语言编写程序,求S=1+(1/2!)+(2/3!)+·····+(n/(n+1!)),直到最后一项的绝对值小于10^-5用C语言编写程序,求S=1+(1/2!)+(2/3!)+·····+(n/(

用C语言编写程序,求S=1+(1/2!)+(2/3!)+·····+(n/(n+1!)),直到最后一项的绝对值小于10^-5
用C语言编写程序,求S=1+(1/2!)+(2/3!)+·····+(n/(n+1!)),直到最后一项的绝对值小于10^-5

用C语言编写程序,求S=1+(1/2!)+(2/3!)+·····+(n/(n+1!)),直到最后一项的绝对值小于10^-5
#include "stdio.h"
double calcS(double t)
{
int i = 1;
double retValue = 0;
double sglValue = 1;
double dFenzi = 0;
double dFenmu = 1;
do
{
dFenzi += 1;
dFenmu *= (i+1);
sglValue = dFenzi/dFenmu;
retValue += sglValue;
}while(sglValue > t);
return retValue;
}
void main()
{
printf("calcS(0.00001) = %lf",calcS(0.00001));
}