c++怎样编写阶乘的和
1!+2!+3!+4!+5!怎么编写

unsigned foo( unsigned n ) { unsigned r = 0; for( unsigned i=0,t=1; i!=n; t*=++i+1 ) r += t; return r; } #include <iostream> using namespace std; int main( void ) { cout << foo(0) << endl; cout << foo(1) << endl; cout << foo(5) << endl; }