語法:
#include <cstdlib>
#include <iostream>
using namespace std;
int N;
long A(int n)
{
return (N-n);
}
int main(int argc, char *argv[])
{
int n;
long sum=0;
printf("請輸入階層數:");
cin >> N;
for(n=1; n<=N; n++){
cout << n << "*[1*(N-" << n-1 << ")]";
sum=sum+(n*A(n-1));
if(n<N){
cout << " + ";
}else{
cout << "=" << sum << '\n';
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
以上當然可以簡化