11. Counter, Arithmetic Mean and Division by Zero

Exercises

Note: while solving the following problems, be careful to always use the type double for the sums (in exercise 1). The reason why you should do that lies in the fact that dividing two values that are both of type int will give a different result compared to the case where one or both values are of type double. We will have a lot more to say on this topic in one of the following chapters.

  1. Write a program that reads in 6 numbers and then writes out the arithmetic mean of the given numbers.
  2. Write a program that reads in a natural number n and then reads in n numbers. It should print out the product of all the given n numbers.
  3. Write a program that reads in a natural number n and then writes out the product of n factors that are all equal to number 2. That is, it should write out the result of raising a number 2 to the power n.
  4. Write a program that reads in a number b and a natural number e. The program should write out the product of e factors that are all equal to the number b. That is, it should write out the number b raised to the power e.
  5. Write a program that reads in 10 natural numbers, then writes out the number of times the second input value appears among them.
  6. Write a program that reads in 10 numbers, then writes out the smallest input value and the number of times the smallest value appears.

Click here for solutions