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.

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

  1. It seems easier to left, strictly on the condition made

  2. Hello. I did not understand one thing about the second problem. The task was: fill the array, consisting of odd numbers of 1 to 99.
    In answer to the problem I saw another. the array has been created[50] with even and odd numbers from 1 to 99. And then, using if conditions are displayed only odd elements. But it does not mean, that was created by an array of only the odd numbers. cout does not write the new elements in the array, and stupidly displays the odd numbers. If we ask again to display an array of ourArr[i], it displays the array and the even and odd numbers. A task, in my opinion, It solved not correctly. If I'm wrong, you are welcome, explain to me…
    Thank you)

    1. How do I it seems, in the 2nd task properly formulated condition tasks, rather than its solution. It should be something like:
      – fill a 50-element array occasional odd numbers in the range [1…100].

      And the solution of this problem given proper (one possible).

    2. The problem is solved correctly. Step into the ring only if the number of changes in the array even, otherwise the cycle will be repeated until the number is not even( i ++ only with an even number)

    3. It is true there is only one array , but its value is correct, since the function rand, It has the same masivi only uyavnim. And in our array zakladivaem only numbers strictly the drain. And when the second time we vivodit, he, too, it is true vivedet, They have been put to E 50 meaning, I hope to ve learned)
      I apologize for the broken Russian)

  3. children, how do you imagine the solution of the first problem, in your reply, if you have not been shown how to do it randomly number. then there are, This task implies in itself the, that has not yet passed. and this is not the first time the way. Programming is based on logic, but in this case it is not observed.

    1. to the task of writing the top,”Getting to the solution of tasks, read articles Arrays in C ++ and the random number generator rand(), if you have not read them.

      1. yes, just. thanks for the answer. although errors still missing, of course.

    2. And you throw off the link,where clearer and better explains the basics, and if we talk about mistakes,what lay!One mistake already indicated…

      1. tpojuh, who have stood up for us so, but you )) Thank you, kommentiruesh that article and respond to user comments.

      2. even if it is nowhere clearer, This fact does not mean, that we should not strive for good, and should leave, breakwater, and so will descend. + Won, higher, mistake already indicated. the wording in the second task is not correct. but do not get me wrong, I say all this not because against, but because of. just wanted to, what would be better.

      3. Aytekin, everything is fine. At you no one takes offense )
        If possible, and if there is free time we will improve.

  4. I sold all of Java. Suddenly you are interested.
    1 The task:

    2 The task:

    3 The task:

  5. I think, the second task is easier to do so:
    do{
    ourArr[i] = 1 + rand() % 100;
    }while(ourArr[i] % 2 == 0);

  6. Zrastvuyte. I wanted to learn how to insert before each positive element of the array zero value

    1. In C / C ++ nezzya “insert” elements in the array.
      can only rewrite values ​​in another array, bigger size, Where, rewriting, you will some elements set to zero.

    1. srand() – this initialization entry value sequence generator (pseudo)random values.
      As the initialization values ​​used present time time( NULL ).
      Such things are done for, to the next program starts let's not repeat (random) the value of the. This is very bad for debugging this code.

    1. If “here” – it comments, It is here, and you can not and do not need to put your code.
      These comments are not in order!

Leave a Reply

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