L5_T2

 avatar
unknown
c_cpp
2 years ago
1.3 kB
4
Indexable
#include <iostream>
#include <cstdlib>

using namespace std;

const int N = 100;
const int MAX_RAND = 20;

void InitArray(int *, int);
void PrintArray(int *, int);
void PowElement(int *, int);

int main()
{
    int arr[N];
    int n;
    
    cout << "Enter array size: ";
    cin >> n;
    
    cout << endl;
    
    InitArray(arr, n);
    PrintArray(arr, n);
    
    cout << "Array after an operation: ";
    PowElement(arr, n);
    PrintArray(arr, n);
    return 0;
}

void InitArray(int *arr, int n)
{
    for(int i = 0; i < n; i++)
    {
        arr[i] = rand() % MAX_RAND + 1 > 10 ? -rand() % MAX_RAND + 1 : rand() % MAX_RAND + 1;
    }
    cout << "The array is initialized" << endl;
}
void PrintArray(int *arr, int n)
{
    cout << endl;
    for(int i = 0; i < n; i++)
    {
        cout << ' ' << arr[i];
    }
    cout << endl;
}
void PowElement(int *arr, int n)
{
    int sign = arr[0];
    int tempIndex = 0;
    if(sign > 0)
    {
        for(int i = 0; i < 0; i++)
        {
            tempIndex = arr[tempIndex] < arr[i] ? i : tempIndex;
        }
        arr[tempIndex] = pow(arr[tempIndex], 3);
    }else{
        for(int i = 0; i < 0; i++)
        {
            tempIndex = arr[tempIndex] > arr[i] ? i : tempIndex;
        }  
        
        arr[tempIndex] = pow(arr[tempIndex], 2);
    }
}
Editor is loading...