用for語句循環不用函數?
int main()
{
int n,s=0;
cout<<"請輸入正整數n:";
cin>>n;
for(int i=1;i<=n;++i)
{
int m=1;
for(int j=1;j<=i;++j)
m*=j;
s+=m;
}
cout<<"\ns=1!+2!+3!+...+n!= "<<s;
}
用for語句循環不用函數?
int main()
{
int n,s=0;
cout<<"請輸入正整數n:";
cin>>n;
for(int i=1;i<=n;++i)
{
int m=1;
for(int j=1;j<=i;++j)
m*=j;
s+=m;
}
cout<<"\ns=1!+2!+3!+...+n!= "<<s;
}