0
What is the error in my c code
#include <stdio.h> int main () { int n, count = 0, rem, t, l, r, i; scanf ("%d", &t); while (t--) { scanf ("%d",&l); scanf ("%d",&r); if(r<4444)printf("0"); for (i=4444;i<=r;i++) { n=i; printf("%d\n",n); while (n != 0) { rem = n % 10; if (rem == 4 || rem == 7) ++count; i /= 10; } //printf("Number of digits: %d", count); if (count == 4 || count == 7) printf ("lucky number"); else printf ("not lucky number"); } } return 0; }
3 Antworten
+ 1
This is not a java code
+ 1
#include <stdio.h>
int main ()
{
int n, count, rem, t, l, r, i;
scanf ("%d", &t);
while(t--)
{
scanf("%d",&l);
scanf("%d",&r);
if(r < 4444)
{
printf("Lucky number starts from 4444\n");
continue;
}
if(l >= r)
{
printf("Invalid search range %d ~ %d\n", l, r);
continue;
}
for(i = l; i <= r; ++i)
{
n = i;
count = 0;
//printf("%d\n", n);
while (n)
{
rem = n % 10;
if (rem == 4 || rem == 7)
++count;
n /= 10;
}
//printf("Number of digits: %d", count);
if (count == 4 || count == 7)
printf ("%d Lucky number\n", i);
//else
// printf ("%d Not lucky number\n", i);
}
}
return 0;
}
0
Bala Krishna where did you see this way to check lucky number? lucky number theory in wiki is different ...