怎样编程1+2*3+4*5*6+7*8*9*10,,,到n项的运算呢??帮帮忙吧

来源:百度知道 编辑:UC知道 时间:2024/09/20 06:57:36
需要简单的编程
希望能够简单的编程

kissyou233是正确的。但是我想我这个可能更好理解点
#include "iostream.h"

void method();

int main()
{
method();
return 0;
}

void method()
{
int sum=0,NUM;
cout<<"Please input NUM: ";
cin>>NUM;
for (int i=1,j=1; i<NUM; i++,j++)
{
int temp=i,k=1;
while (k<j) {
i++;
temp*=i;
k++;
}
sum+=temp;
}
cout<<sum<<endl;
}

#include<iostream>
using namespace std;

void main() //1+2*3+4*5*6+7*8*9*10,,,到n项的运算
{
int n, k = 1, x = 1;
int sum = 0, mul;
cout<<"pls input a number"<<endl;
cin>>n;
while(x<=n)
{
mul = 1;
for(int i=0; i<k && x<=n; i++, x++)
mul *= x;

k++;
sum += mul;
}

cout<<"res:"<<sum<<endl;
}

#inc