### Problem statement

This program take any number from user and check it is *self-descriptive* number or not.

### What is *self-descriptive* number?

A number is called as *self-descriptive* when the position of digit represents the number of time it appears in that number.

There are so many numbers are *self-descriptive*.

For example:

1 2 3 |
1210, 2020, 21200, 3211000, 42101000 etc |

Consider 2020,

- position 0 has value 2 and there are two 0s in the number;
- position 1 has value 0 and there are no 1s in the number;
- position 2 has value 2 and there are two 2s in the number;
- position 3 has value 0 and there are zero 3s in the number.

Now consider a *self-descriptive* number 6210001000,

- contains 6 at position 0, indicating that there are six 0s in 6210001000;
- It contains 2 at position 1, indicating that there are two 1s in 6210001000;
- It contains 1 at position 2, indicating that there is one 2 in 6210001000;
- It contains 0 at position 3, indicating that there is no 3 in 6210001000;
- It contains 0 at position 4, indicating that there is no 4 in 6210001000;
- It contains 0 at position 5, indicating that there is no 5 in 6210001000;
- It contains 1 at position 6, indicating that there is one 6 in 6210001000;
- It contains 0 at position 7, indicating that there is no 7 in 6210001000;
- It contains 0 at position 8, indicating that there is no 8 in 6210001000;
- It contains 0 at position 9, indicating that there is no 9 in 6210001000.

### Program

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
#include<stdio.h> int check(int,int); int getNumDigits(int); int main() { int num=0,temp=0, digit=0,count=0; printf("enter the number\n"); scanf("%d",&num); temp=num; int flag = 1; int numDigit = getNumDigits(temp); while(temp>0) { digit=temp%10; int count=check(num,numDigit); if(count!= digit) { printf("\tNumber is not a self descriptive"); flag = 0; break; } temp=temp/10; numDigit--; } if(flag) { printf("\tNumber is a self descriptive"); } } /* check number of times the digit appear in number */ int check(int num,int digit) { int count=0; while(num>0) { if(num%10 == digit) { count++; } num=num/10; } return count; } /* to check number of digits in number */ int getNumDigits(int num) { printf("%d",num); int digits = 0; while(num>0) { digits++; num=num/10; } return digits-1; } |

**Output**

1 2 3 4 |
enter the number 3211000 Number is a self descriptive |