Video courses for company/skill based Preparation
(Check all courses)Get Prime Video
Purchase mock tests for company/skill building
(Check all mocks)Get Prime mock
C program to count number of times x digit occurs in each and every number from 0-n
Number of times x digit occurs in each number from 0 to n
In this C program, we will be counting the occurrence of a single digit in a number or from a group of digits. The number can be of any length starting from one to infinity, and Number can be ranging between -infinity to +infinity if we talk about numbers only. Other than these numbers can be divided into different groups like:
Etc. In this case, we will be counting the occurrence of a digit in a number without being specific to its type and its range.
- Step 1:- Start.
- Step 2:- Take input from the user.
- Step 3:- Take input of a digit whose occurrence is to be found.
- Step 4:- Change the datatype of the integer inputs.
- Step 5:- use the count function to count the occurrence of the digit and print it.
- Step 6:- End.
C Program for occurrence of a Digit
int number, digit;
int count = 0;
printf("Enter the number : ");
printf("Enter the digit : ");
int rem = number%10;
number = number/10;
printf("Digit count is %d",count);
Output Enter the Number : 897982 Enter the digit : 9 Digit count is 2