lucky no is the number which must contains 1 or 7 or 9
the following program returns count of lucky numbers
int range 1 to n
i/p 175
o/p 16
i/p 20
o/p 6
#include<stdio.h>
int main() {
int ctr=0,n,digit,rem,no,num,lcount=0;
scanf("%d",&n);
no=n;
while(no>=1)
{
num=no;
while(num)
{
digit=num%10;
if(digit==1||digit==7||digit==9)
{
num=num/10;
continue;
}
else
break;
num=num/10;
}
if(num==0)
lcount++;
no--;
}
printf("\n%d",lcount);
}
the following program returns count of lucky numbers
int range 1 to n
i/p 175
o/p 16
i/p 20
o/p 6
#include<stdio.h>
int main() {
int ctr=0,n,digit,rem,no,num,lcount=0;
scanf("%d",&n);
no=n;
while(no>=1)
{
num=no;
while(num)
{
digit=num%10;
if(digit==1||digit==7||digit==9)
{
num=num/10;
continue;
}
else
break;
num=num/10;
}
if(num==0)
lcount++;
no--;
}
printf("\n%d",lcount);
}
No comments:
Post a Comment