#include <stdio.h>
#include <stdlib.h>
int main()
{
long num;
int digit,rem,count=0;
printf("Enter the Number: ");
scanf("%ld",&num);
printf("Enter the digit to be counted:");
scanf("%d",&digit);
while(num!=0)
{
rem=num%10;
if(rem==digit)
count++;
num=num/10;
}
printf("The digit %d present %d times ",digit,count);
}
IF i have a modified version of it, then can u code?
ReplyDeleteinstead of asking from the user which no to check for occurrence, cant u design the code to check for itself the digits and is occurrences.
eg. 12223
shall output 1- 1time
2- 3 times
3-1 time
Try this code :)
Delete// C program to find the occurence of the number
#include
#include
int main()
{
int a[10];
int number,num,i,temp=0;
printf("Enter the number");
scanf("%d",&number);
for(i=0;i<10;i++)
{
a[i]=0;
}
num=number;
while (num>0)
{temp=num%10;
num=num/10;
a[temp]++;
}
for(i=0;i<10;i++)
{
if (a[i]>0)
printf("%d present %d times\n",i,a[i]);
}
return 0;
}
// C program to find the occurence of the number
ReplyDelete#include
#include
int main()
{
int a[10];
int number,num,i,temp=0;
printf("Enter the number");
scanf("%d",&number);
for(i=0;i<10;i++)
{
a[i]=0;
}
num=number;
while (num>0)
{temp=num%10;
num=num/10;
a[temp]++;
}
for(i=0;i<10;i++)
{
if (a[i]>0)
printf("%d present %d times\n",i,a[i]);
}
return 0;
}
main()
ReplyDeleteint num,rem,I;
int d[10]={0};
printf ("Enter a no ");
scanf ("%d",&num);
for(i=num;i!=0;i++)
{
rem=i%10;
d[rem]++;
}
for(i=0;i<10;i++)
printf ("%d occurs %d times\n",i,d[i]);
}