0
我得到奇怪的錯誤與雙元素和,它看起來像1e + 002,當答案是雙和。double array的總和得到不正確的答案e
const int ARRAY_SIZE =20;
//Index variable
int i;
//For finding average
double sum=0.00;
cout.precision(2);
srand((unsigned)time(0));
double main_array[ARRAY_SIZE];
//Header
cout << "Element number \t\t" << "Random Number\n\n" << endl;
//Assigning random values into array.
for (i=0; i< ARRAY_SIZE; i++)
{
//Randomizer
double ran =(rand()/((float)RAND_MAX/(10-0)));
main_array[i] = ran;
sum+=main_array[i];
1E + 002 = 1×10^2 = 100,如果有幫助 –
你的算法似乎是隨機的。你期望什麼答案,爲什麼你認爲生成的答案是不正確的? – user2079303