用户输入数组长度和数组元素最大值
//i!*2^i
#include<iostream>
using namespace std;
void sum()
{
int a;//数组长度
int b;//数组元素最大值
cout << "输入数组长度和数组元素最大值" << endl;
cin >> a >>b;
int *top = new int[a];
*top = 1;
cout << "i等于0时=";
cout << *top << endl;
for (int i = 1; i < a; i++)
{
int value = 1;
for (int j = 1; j <= i; j++)
{
value *= 2;
value *= j;
}
if (value >= b) cout << "数组太长,超出最大值" << endl;
else if (i == a - 1)
{
*top = value; cout <<"i等于"<< i<<"时="; cout << *top << endl;
}
else
{
*top = value; cout << "i等于" << i << "时="; cout << *top << endl; top++;
}
}
}
void main()
{
sum();
system("pause");
}