当我运行以下内容时,只有大数字出现但是,“最小元素的倍数”的数字不显示。
我还看不出代码有什么问题。建议表示赞赏。
int A[15];
void fill(int arr[], int n, int left, int right)
{
for (int i = 0; i < n; i++)
arr[i] = rand() % (right - left + 1) + left;
}
void output(int arr[], int n, int w)
{
for (int i = 0; i < n; i++)
{
cout << setw(w) << arr[i];
}
cout << endl;
}
int findMinElem(int arr[], int n)
{
int minelem = arr[0];
for (int i = 0; i < n; i++)
{
if (arr[i] % minelem == 0) minelem = arr[i] ;
return true;
}
return false;
}
int main()
{
int n = 15;
fill(A, n, 0, 50);
output(A ,n , 15);
if (findMinElem(A, n ))
cout << "Multiples of the minimum elements =\n";
else
cout << "No multiples of the minimum element elements\n";
system("pause");
return 0;
}