Find the number of times digit 3 occurs in each and every number from 0 to n

Find the number of times digit 3 occurs in each and every number from 0 to n

find the number of times digit 3 occurs in each and every number


A program to find the number of times digit 3 occurs in each and every number from 0 to n is discussed here. Given a number n as input, count the number of 3s occurring in all the numbers from 0 to n.

For example,

Input: 100

Output: 20

The total number of 3s that appear from numbers 0 to 100 are {3, 13, 23, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 53, 63, 73, 83, 93}


Find the number of times digit 3 occurs in each and every numberClick here to learn more about FACE Prep PRO


Algorithm to find the number of times digit 3 occurs in each and every number

  1. Input the number n from the user.
  2. Initialize count = 0.
  3. Repeat for all numbers from o to n.
  4. Find if num % 10 == 3
  5. Increment count
  6. Divide the number by 10 and from step 4.
  7. Return count.

The program to find the number of times digit 3 occurs in each and every number from 0 to n is given below.

@@coding::1@@


Time complexity: O(n)

Recommended Programs


Program to find the number of times digit 3 occurs in each and every number from 0 to n is discussed here. Given a number n as input, count the number of 3s occurring in all the numbers from 0 to n.  For example,  Input: 100  Output: 20

c