Question: My question is not about algorithm, but something confusing about C programming language.
I met a problem as below:

**Problem description**

N! (N factorial) can be quite irritating and difficult to compute for large values of N. So instead of calculating N!, I want to know how many digits are in it. (Remember that N! = N \* (N - 1) \* (N - 2) \* ... \* 2 \* 1) 

**Input**

Each line of the input will have a single integer N on it 0 < N < 1000000 (1 million). Input is terminated by end of file. 

**Output**

For each value of N, print out how many digits are in N!. 

My code is like that:

```
 #include<stdio.h>
 int main()
{
    int n ;
    while(scanf("%d",&n)&&n!=EOF)//1
    //while(scanf("%d",&n)!=EOF)//2
    {
        int result=1;
        int i;
        double temp = 1;
        for(i=n;i>0;i--)
        {
            temp*=i;
            while((temp/10)>1)
            {
                result++;
                temp=temp/10;
            }           
        }
        printf("%d\n",result);
    }
    return 0;
}

```

When I used `while(scanf("%d",&n) && n!=EOF)`, the Online judge I was using showed that `Time Limit Exceeded`,when I changed it to `while(scanf("%d",&n)!=EOF)`, every thing goes well.I think `n!=EOF` may take too much time, So what is the essence of `EOF` ?

Answer: 
Neither condition is proper one to use (but the one with `scanf("%d", &n) != EOF` is the better one to use).

The loop should be written as:

```
while (scanf("%d",&n) == 1)

```

because you're asking `scanf` to convert 1 value, and the return value from `scanf` is the number of items successfully converted.
```
I would strongly suggest using the following code rather than 
the illmannered scanf() function:

#include<stdio.h>

int main()
{
    unsigned int n ;            // user input after conversion
    long long int result=0;     // maybe use uint64_t
    char inArray[100] = {'\0'}; // user input array
    int i;                      // loop counter
    int digitCount = 0;         // number of digits to display factorial value

    printf("\nwhen enter a number\n"); 
    printf(" then pgm will output factorial for that number\n");
    printf(" then number of digits in factorial value\n");

    printf("\n\nPlease enter first number: (or <ctrl-z> to exit)");
    while( NULL != fgets( inArray, sizeof(inArray), stdin )
    {
        n = (unsigned)atoi( inArray );
        if( 0 == n )      {result = 0;}
        else if( 1 == n ) {result = 1;}
        else if( 2 == n ) {result = 2;}
        else
        {
            result = n;
            for(i=(n-1);i>1;i--)
            {
                result *= i;
            } // end calculate factorial
        } // end if

        printf("factorial value: %lld\n",result);

        // setup work area usage
        memset( inArray, 0x00, sizeof(inArray) );
        sprintf( inArray, "%lld", result );

        // calculate and display number of digits
        digitCount = strlen(inArray);
        printf("digit count: %d\n", digitCount );

        // clear work area and prompt for next input from user
        memset( inArray, 0x00, sizeof(inArray) );
        printf("\n\nPlease enter next number: (or <ctrl-z> to exit)");
    } // end while

    return 0;
} // end function: main

```