# Program to check the occurence of digit in a given number

This program checks the occurrence of digit 5 in a given number.

```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #include "conio.h" #include "stdio.h"   void main() { int num,i,n,k; printf("\nEnter a number : "); scanf("%d",&num); n=num; i=0; while(n!=0) { k=n%10; n=n/10; if(k==5) { i++; } } printf("\nThe occurrence of 5 is %d times",i); getch(); }```

Output:

```Enter a number : 21353 The occurrence of 5 is 1 times```

### 7 Responses to “Program to check the occurence of digit in a given number”

1. please what is meaning of this expression: k = n%10

• n%10 means simply it will give you the last digit of given number.

Ex: 1%10=1;
EX: 22%10= 2 , 2(if we keep this in loop)

2. /*Works for all n…. below Code not tested, but should work*/

/*Previous code*/
…………
…………
printf(“\nEnter a number : “);
scanf(“%d”,&num);
printf(“\n Enter the digit you would like to search for its repeatation”);
scanf(“%d”, &digit);
n=num;
i=0;
while(n!=0)
{
k=n%10;
n=n/10;
if(k==digit)/*comparing with entered digit number*/
………..
…………
/*Then rest of the code above follows*/

3. @Jhonson:-
Expression k = n % 10;
/* It means if n % 10 results you 5
it gives the reminder value
then next line says if k == 5
then increaes the counter*/

I hope this helps

4. vaibhav

I want to return a digit which occurs maximum time in a given number

5. I want a programme in which the position of even no. Will be displayed within the no. Given by the user

6. can someone help me to write this in flowchart,please

##### More from Simple programs
###### Program to find out whether a entered number is divisible by 3 and 5 or not ### Research Papers ### Projects 