Assume The Motor Vehicles Department has notified numbers between 1000 and 9999(both inclusive) as available for the new series KL-35 A. Write a program to print all fancy numbers in this series. Following

are the conditions for fancy numbers:

1. All digits are the same.

2. Sum of all digits added until getting a single digit gives the number 9.

//find fancy number

#include<stdio.h>

#include<conio.h>

int all_the_same(int x);

void main()

{

int n,s=0,sum=0,i,d,kond;

clrscr();

printf("Fancy numbers between 1000 and 9999 are");

for(kond=1000;kond<=9999;kond++)

{

n=kond;s=0;sum=0;

if(all_the_same(n)==1)

{

printf("\n%d ", n);

getch();

}

else

{

while(n>0)

{

d=n%10;

s=s+d;

n=n/10;

}

while(s>0)

{

i=s%10;

sum=sum+i;

s=s/10;

}

if(sum==9)

{

printf("\n%d ",kond);

getch();

}

}

}

getch();

}

int all_the_same(int x)

{

int cnt=0;

int digit = x%10;

while(x>0)

{

if((x%10) != digit)

cnt++;

x = x/10;

}

if(cnt==0)

{

cnt=0;

return 1;

}

else

{

return 0;

}

}

## No comments:

## Post a Comment

Note: only a member of this blog may post a comment.