C Program check whether there are repeated digits in given number
#include<stdio.h>
main()
{
int num,k,temp,frequency[9],flag=0,i;
printf("Enter number to find which digits are repeated\n");
scanf("%d",&num);
temp=num;
//By default setting frequency of digits as zero
for(i=0;i<10;i++)
{
frequency[i]=0;
}
while(num>0)
{
k=num%10;
frequency[k]++;
num/=10;
}
for(i=0;i<10;i++)
{
if(frequency[i]>1)
{
flag=1;
printf("%d --> repeated %d times\n",i,frequency[i]);
}
}
if(flag==0)
{
printf("No Repeated Digits\n");
}
else
{
printf("Repeated digits are there\n");
}
}
Output:-
Enter number to find which digits are repeated
12116744
1 --> repeated 3 times
4 --> repeated 2 times
Repeated digits are there
Post a Comment
If you have any doubts, Please let me know
Thanks!