I am writing a program in which user enter any value and the program calculates the occurence of any digit in a number. For example, if user enter 4323122 the output should like this
3 is present 2 times in a number.
2 is present 3 times in a number.
The code I have written is here but there is a mistake which i am unable to resolve.
Code:
#include<stdio.h>
int main(void)
{
int num, m, div=1, rem, count=0, i,n, a;
printf("Enter Number: ");
scanf("%d", &num);
div=num;
for(i=1; i<=10; i++)
{
div=num;
while(div!=0)
{
rem=div%10;
div=div/10;
if(i==rem)
{
count++;
}
if(i==rem && count>=2)
{
printf("\n%d is present %d times", i, count);
}
}
}
return 0;
}