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 task:
    int main()
    {
    srand(time(NULL));
    const int SIZE=10;
    int arr[SIZE];
    for (int i = 0; i < SIZE; i )
    {
    arr[i] = rand() %7 +7;
    cout << arr[i] <= 10)
    {
    arr[i] -= 10;
    }

    }
    cout << endl;
    for (int i = 0; i < SIZE; i )
    {
    cout << arr[i] << "\t";
    }
    return 0;
    }

  2. The third task is the arithmetic mean value, in some cases it is not an integer. Perhaps it would be better two variables sum & averageValue burn through double.

    Thank you for your video tutorials and assignments to them!!!

  3. #include
    #include
    #include
    using namespace std;

    int main()
    {
    const int SIZE = 10;
    int array[SIZE] = {};

    srand(time(NULL));
    for(int i = 0; i < SIZE; i )
    {
    array[i] = 7 + rand() % 8;
    cout << setw(3) << array[i];
    }

    cout << endl<<"——————————"<<endl;

    for(int i = 0; i = 10)
    {
    array[i] -= 10;
    }
    cout << setw(3) << array[i];
    }
    return 0;
    }

  4. Here is 3 the task, I have it in one cycle laid:)
    #include
    #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “Russian”);
    srand(time(NULL));
    const int SIZE = 10;
    int masiv1[SIZE];
    int masiv2[SIZE];
    int masiv3[SIZE];
    int max=0, min=60,sum=0;
    float;
    for (int i = 0; i < SIZE; i )
    {
    masiv1[i] = rand() % 20 + 10;
    masiv2[i] = rand() % 20 + 10;
    masiv3[i] = masiv1[i] + masiv2[i];
    sum + = masiv3[i];
    cout << "Первый " << masiv1[i] << " Second " << masiv2[i]<<" Третий "<<masiv3[i] < max)
    {
    max = masiv3[i];
    }
    if (masiv3[i] < min)
    {
    min = masiv3[i];
    }

    }
    cout << endl;
    to = (float)sum / SIZE;
    cout << "Среднее арефметическое элементов третего массива: " << to << endl;
    cout << "Вот минимальный элемент массива: " << min << endl;
    cout << "Вот максимальный элемент массива: " << max << endl;
    }

  5. HELP.
    In the given array F[12] determine the number of even elements. If this amount is more 6, display every second element of the array. Otherwise, display all negative elements. Display the resulting array on the screen.
    Note: complete the task displaying the main functions in separate methods.

    1. #include
      #include

      using namespace std;

      const int SIZE = 12;

      int main()
      {
      int F[SIZE];
      int summ1 , summ2 = 0;
      srand(time(NULL));
      for (int i = 0;i < SIZE;i )
      {
      F[i] = -10 + rand() % 20;
      if (F[i] % 2 == 0)
      {
      summ1++;
      }
      if (F[i] % 2 != 0)
      {
      summ2++;
      }
      }
      for (int i = 0;i < SIZE;i )
      {
      cout << "F[" << i << "] = " << F[i] << endl;
      }
      cout <= 6)
      {
      for(int i = 1;i < SIZE;i = i + 2)
      {
      cout << "F[" << i << "] = " << F[i] << endl;
      }
      }
      if (summ1 < 6)
      {
      for (int i = 0;i < SIZE;i )
      {
      if (F[i] < 0)
      {
      cout << "F[" << i << "] = " << F[i] << endl;
      }
      }
      }
      }
      You purely add everything to the function

  6. Creating arrays X(20), Y(20). Построение массива D(20) как разница между большим и меньшим из соответствующих элементов массивов X,Y. Расчет Dsr. Расчет массива D отрицательного количества (k). D регулирование массива в порядке убывания.

Leave a Reply

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