Total Occurrance Given two integer numbers input1 and input2, find the total number of occurrences of input1 in a series of natural numbers from 0 till input2. Note: 1. input1 will be within 1-9 and 1. input2 will be within 1 – 100. Prototype: public int findTotalOccurrence(int input1, int input2) Example 1: input1 = 2 input2 = 20 output = 3 Explanation: Number 2 is repeated 3 times in the series of natural numbers from 0 - 20 ie at 2, 12, 20. Example 2: input1 = 2 input2 = 30 output = 13 Explanation: Number 2 is repeated 13 times in the series of natural numbers from 0 – 30 i.e. at 2, 12, 20, 21, 22 (occurred twice), 23, 24, 25, 26, 27, 28, 29​

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
Question

Total Occurrance
Given two integer numbers input1 and input2, find the total number of occurrences of input1 in a
series of natural numbers from 0 till input2.


Note:
1. input1 will be within 1-9 and
1. input2 will be within 1 – 100.
Prototype: public int findTotalOccurrence(int input1, int input2)

Example 1:

input1 = 2
input2 = 20
output = 3
Explanation: Number 2 is repeated 3 times in the series of natural numbers from 0 - 20 ie at 2,
12, 20.

Example 2:

input1 = 2
input2 = 30
output = 13
Explanation: Number 2 is repeated 13 times in the series of natural numbers from 0 – 30 i.e. at 2,
12, 20, 21, 22 (occurred twice), 23, 24, 25, 26, 27, 28, 29​

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Lower bounds sorting algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr