紫衣仙女
方法1#include<stdio.h>void main(){float e,a; int i,n=0; /*涉及到小数运算要用浮点型变量*/e=1,a=1; /*a=1在后面有乘积运算*/for(i=1;1/a>1e-5;i++) /*条件循环语句*/{a*=i; /*级乘的算法*/e+=1/a ; /*e的运算方法*/n++;}printf("%f,n=%d\n",e,n);}方法2#include <stdio.h>int main( ){float s = 1, n = 1;int t = 1;while ( 1 / n >= 0.00001 ){s+=1/n;t++;n=n*t;}printf("%f,n=%d\n", s,t);return 0;}方法3#include<stdio.h>void main(){int i=1,j=1;float e=1.0,k;do{j=i*j;k=1.0/j;e=e+k;i++;}while(k>1e-5);/*判断误差是否小于给定的误差限E=0.00001 */printf("%f,n=%d\n",e,i);}