L4_T2

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.0 kB
2
Indexable
#include<iostream>
#include<cstdlib>

using namespace std;

const int MAX_RAND = 10;

void NewInitArray(int *, int);
void PrintArray(int *, int);
int GetOddCount(int*, int);

int main()
{
    int n;
    
    cout << "Enter array size" << endl;    
    cin >> n;
    
    int *array = new int[n];
    
    NewInitArray(array, n);
    
    cout << "Initialized array: " << endl;
    
    PrintArray(array, n);
    
    cout << "The odd numbers count: " << GetOddCount(array, n);
    
    delete []array;
    
    return 0;
}

void NewInitArray(int *arr, int n)
{
    for(int i = 0; i < n; i++)
    {
        arr[i] = rand() % MAX_RAND;
    }
    cout << "The array is initialized" << endl;
}
void PrintArray(int *arr, int n)
{
    
    for(int i = 0; i < n; i++)
    {
        cout << ' ' << arr[i];
    }
    cout << endl;
}
int GetOddCount(int *arr, int n)
{
    int oddCount = 0;
    //cout << endl;
    for(int i = 0; i < n; i++)
    {
        oddCount = (arr[i] % i == 0) ? oddCount++ : oddCount;
    }
    return oddCount;
}