If I have an array of years for example 1974 1948 1999 1989


If I have an array of years for example 1974 1948 1999 1989 1745 how can I add up all of the years that end in a certain number for example how can I add all of the years in this array that end in 9?

Solution

Answer

i. Take each year from the array and initialize sum to 0

ii. using modulus method, fetch the last digit, i.e. remender = n % 10; this will give you the last digit

iii. check if it is the digit you want

iv. if yes then add this year to sum

v. else, ignore

vi. repeat steps ii to v for all the elements of the array

 If I have an array of years for example 1974 1948 1999 1989 1745 how can I add up all of the years that end in a certain number for example how can I add all o

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site