10. Arrays
Exercises
Note: whenever the problem states that program has to read in different numbers, then the program does not need to verify that the input numbers are indeed different. In describing the allowed input data, the problem description limits the possible inputs.
- Write a program that reads in 7 numbers, then prints out all the input values that are smaller than 10.
- Write a program that reads in 7 numbers, then prints out all the input values that are not equal to the smallest one. If you need a hint, see the footnote[*].
- Write a program that reads in 7 numbers, then prints out the sum of all the input values that are not equal to the smallest one.
- Write a program that reads in a natural number n and then reads in n numbers. It should print out the sum of all the given n numbers that are smaller than the last given number.
- Write a program that reads in 8 different numbers, then writes out the position of the smallest one in the input sequence as a number from 1 to 8. If you need a hint, see the footnote[*].
First, the program should read in input values. Then it should find the smallest value. After that it should output what is required. All in all, there should be three for
loops.
There was a similar problem in the exercises two chapters back, so look there. Also, have in mind that the position to be output is a value from 1 to 8, while in C++ array indices start from 0.