函数,用于最小元素

时间:2017-01-03 22:49:40

标签: c++

当我运行以下内容时,只有大数字出现但是,“最小元素的倍数”的数字不显示。

我还看不出代码有什么问题。建议表示赞赏。

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;
}

0 个答案:

没有答案