The basics of programming in c++ for beginners

Tasks: One-dimensional arrays C ++

Getting to the solution of tasks, read articles Arrays in C++  and The random number generator rand(), if you have not read them.   Try to address the proposed tasks independently and watch our decisions only in extremis.

1. Create an array of type int on 10 elements and fill it with random numbers from 7 to 14. After filling overwrite all numbers, who for more than ten:  from the stored value to take away 10.  For example the number is stored in the cell 12: 12 – 10 = 2. Write to this cell 2 Writing the new value, use composite(combined) statements.

2. To fill an array of elements 50 odd numbers from 1 to 99. (use the operation remainder of the division, to check on the number of parity)

3. Declare three arrays. The first two to fill with random values ​​from 10 to 30. In the third elements of the array to record the amount of the corresponding elements of the first two sets. (in the third cell zero – the sum of zero cells first and second arrays, and so on). Then, find the arithmetic mean of the elements of the third array, the maximum value and minimum value, which it holds.

113 thoughts on “Tasks: One-dimensional arrays C ++

  1. The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) - the size of arrays a and b.

    The second line n are integers - the array elements a (- 109 ≤ to ≤ 109).

    The third line m are integers - the elements of the array b ( - 109 ≤ bj ≤ 109).

    Output

  2. #include
    using namespace std;

    int main (){
    int F[49];
    int b=0;
    int x=0;
    for(int i=0;b<=99;b++) {
    if (b%2==0){
    b++;
    }

    if (b%2==1){
    F[x]=b;
    x++;

    }

    }

    for(int z=0;from<=49;with ++) {

    cout<<"F["<<from<<"]"<<F[from]<<endl;
    }
    }

  3. using namespace std;
    int main()
    {
    setlocale(LC_ALL, “Rus”);

    const int size = 10;

    int i = 0;
    int sum = 0;
    int average = 0;
    int ourArr[size] = {};
    int ourArr2[size] = {};
    int ourArr3[size] = {};
    int min = 100;
    int max = 0;

    cout << "Заполняем массивы" << endl;

    for (i = 1; i < 11; i )
    {
    ourArr[i] = size + rand() % 21;
    ourArr2[i] = size + rand() % 21;
    ourArr3[i] = ourArr[i] + ourArr2[i];
    cout << ourArr[i] << " | ";
    cout << ourArr2[i] << " | ";
    cout << ourArr3[i] < max)
    max = ourArr3[i];
    if (ourArr3[i] < min)
    min = ourArr3[i];
    }
    cout << "Максимум = " << max << endl;
    cout << "Минимум = " << min << endl;
    cout << "Среднее арифм. = " << average << endl;
    }

  4. Help
    Find amount 5 largest elements of one-dimensional array A (20) and geometric environment?

  5. Find amount 5 largest elements of one-dimensional array A (20) and geometric environment?
    С

  6. The air temperature was measured 30 once a day, which is expressed in a one-dimensional array. How much is the average daily temperature during the day?
    С
    Help please

  7. help me please!
    One-dimensional array A is given(10) . If there are two zeros before the maximum element, then increase all positive elements in 2 fold
    С

  8. #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);

    const int SIZE = 50;
    int array[SIZE] = {};
    int a = 0;

    for (int i = 0; i <= 99; i )
    {
    if(i % 2 != 0)
    {
    array[i] = i;
    cout << a << "-я ячейка массива содержит " << array[i] << endl;
    a++;
    }
    }

    system("pause");
    return 0;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *