当前位置:网站首页>1089: highest order of factorial

1089: highest order of factorial

2022-07-07 07:17:00 Huaze flowers

Title Description

Enter a positive integer n. Output n! The number on the highest digit of .

Input

Enter a positive integer n(n No more than 1000).

Output

Output n! The number on the highest digit of .

The sample input

1000

Sample output

4

Tips

Be careful double Type overflow problem .

Code :

//n The factorial 
// Input :
//1000
// Output :
//4


#include <stdio.h>
int main ()
{
    double sum=1.0;
    int n,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        sum*=i*1.0;
        while(sum>=10)
        {
            sum=sum/10;
        }
    }
    printf("%.0lf",sum);
    return 0;
}

Running results :

Submit :

 

 

原网站

版权声明
本文为[Huaze flowers]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130716522433.html