Five exercises on numbers that will help you develop your logic

Five programming exercises with numbers that will help you develop your logic.

Find the largest number from the following series of 7 numbers

In this exercise you have to the find the largest number from the following series

10,12,15,3,5, 22, 2

Hint:

  • Store the numbers in an array
  • Make use of temp variable to store the greater when comparing 2 of them
  • Write a for loop to compare all the other numbers

Find the middle number from the set of 5 numbers

12,18,5,22,13

Please note I do not mean “Median”.  I want you to find the middle number. In case of above series 22 is the largest number and 5 is lowest number and 13 is the middle

Find the mean, median, mode and range from the series of following numbers

23,9,14,2,28,19,3,15,9,25,2,4,9

Hints

  • Mean is the average. Add all numbers and divide it by the count of numbers
  • Median is the middle number, in the above case 19 is the median
  • Mode is the number that is repeated more often than any other number. In this case it is 9
  • Range is the difference between the largest and lowest number. In this case largest is 28 and lowest is 2. So 28-2 is 26

Form the below Matrix

Write a program that will form a matrix like the below table

0 1 2 3 4
1 0 1 2 3
2 1 0 1 2
3 2 1 0 1
4 3 2 1 0

 

Hint:

  • Use a for loop and nested loop

Find the numbers which are not repeated

Identify the numbers which are not repeated in the following series

23,9,14,2,28,19,3,15,9,25,2,4,9