Link to home
Start Free TrialLog in
Avatar of Rishab tata
Rishab tata

asked on

CodeChef Problem - LuckyFour

Link to the problem:

The code works fine on my own system, but while submitting shows wrong answer?

 
   #include <stdio.h>
    void main()
    {
    	int t, n, count;
    	scanf("%d", &t);
    	while(t--)
    	{
    		count=0;
    		scanf("\n%d",&n);
    		while(n>0){
    		if(n%10==4)
    		{
    			count++;
    		}
    		n=n/10;
    	}
    	printf("\n%d", count);
    	}
    }

Open in new window

Avatar of sarabande
sarabande
Flag of Luxembourg image

can you post your inputs and the expected count from that?

note, the

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

Open in new window


should be changed to

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

Open in new window


if doing so, the following code should work:

#include <stdio.h>
void main()
{
    int t, n, count;
    char c;
    scanf("%d", &t);
    while(t--)
    {
        count=0;
        scanf("\n%d",&n);
        while(n>0){
            if(n%10==4)
            {
                count++;
            }
            n=n/10;
        }
        printf("%d\n", count);
    }  
    printf("type any key to end");
    scanf("%d", &t);
}

Open in new window


Sara
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.