Question: (n < 10) write an algorithm
Reply:
Method One:
#include <stdio.h>
int main ()
{
int f[10]={1,1,2,6,24,120,720,5040,40320,362880};
int n;
Double E;
printf ("N e\n");
printf ("------------\ n");
printf ("%d%d\n", 0, 1);
printf ("%d%d\n");
printf ("%d%.1f\n", 2,2.5);
e=2.5;
for (n=3;n<=9;n++)
{
E+=1.0/f[n];
printf ("%d%0.9f\n", n,e);
}
return 0;
}
Method Two: #include <cstdio>
#include <cstring>
#include <cmath>
Int main () {
double E;
int i, TMP;
e = 1; & nbsp
tmp = 1;
printf ("N e\n");
printf ("-- ---------\ n ");
printf ("0 1\n");
for (i = 1; i < ten; i++) {
&n bsp; tmp *= i;
e + = 1.0/tmp;
if (i>=3) printf ("%d%.9lf\n", I, E);
else if (2 = = i) printf ("%d%.1lf\n", I, e);
else printf ("%d%.0lf\n", I, E);
}
return 0;
}
Many methods, original aim, mainly output to pay attention to the format and range on the line.
U Calculate e factorial addition and summation problem