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 |
I want to return a digit which occurs maximum time in a given number
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)