Programming Examples

Write a program to count the occurrence of 0 to 9 digits between 1


Write a program to count the occurrence of 0 to 9 digits between 1 and the given decimal number

Solution

# include <stdio.h>
void main()
{
int t,k,n,l,i;
static int st[10];
clrscr();
printf(“\n Enter a Decimal Number :”);
scanf(“%d”,&n);
for(l=1;l<=n;l++)
{
 t=l;
 while(t!=0)
 {
 k=t%10;
 t=t/10;
 st[k]++;
 }
}
printf(“\occurrence of 0-9 digits between 1 to %d Numbers.”,n);
printf(“\n======= = == === ====== ======= = ========\n”);
for(i=0;i<10;i++)
if(st[i]>0)
printf(“\n %d Occurs %8d Times.”,i,st[i]);
getch();
}
Output

OUTPUT:

Enter a Decimal Number: 15

Occurrence of 0-9 digits between 1 to 15 Numbers.

0 Occurs 1 Times.

1 Occurs 8 Times.

2 Occurs 2 Times.

3 Occurs 2 Times.

4 Occurs 2 Times.

5 Occurs 2 Times.

6 Occurs 1 Times.

7 Occurs 1 Times.

8 Occurs 1 Times.

9 Occurs 1 Times.

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz