求各位C++大神帮忙做道题目 感激不尽。。。。

2024-12-16 14:20:04
推荐回答(2个)
回答1:

#include "stdafx.h"

#include
using namespace std;

#define ARRAY_ELEMNET_NUMBER 40

int GenerateArrayAndCalculateSum(int);

int _tmain(int argc, _TCHAR* argv[])
{
int xMax;
cout<<"Please input xMax:"< cin>>xMax;

cout<<"The sum of the array:\n"< system("pause");
return 0;
}

int GenerateArrayAndCalculateSum(int xMax)
{
//Generate Array
int * Array = new int[ARRAY_ELEMNET_NUMBER];
for(int i=0;i int randomNumber;
do{
randomNumber = rand();
}while(randomNumber>=xMax);
Array[i] = randomNumber;
cout<<"the %d"< }

//Get sum:
int sum =0;
for(int i=0;i sum += Array[i];
}

delete [] Array;
Array = NULL;

return sum;
}

//眼高手低可不好呀~

回答2:

····················································生成40个不大于xMax的随机数很难吗?
数组求和很难吗?这都问人,烧饼