1.题目介绍
2.解题代码
3.疑问
4.解决
1.题目
本题要求实现一个打印非负整数阶乘的函数。
函数接口定义:
void Print_Factorial ( const int N );
其中N是用户传入的参数,其值不超过1000。如果N是非负整数,则该函数必须在一行中打印出N!的值,否则打印“Invalid input”。
裁判测试程序样例:
#include <stdio.h>
void Print_Factorial ( const int N );
int main()
{
int N;
scanf("%d", &N);
Print_Factorial(N);
return 0;
}
/* 你的代码将被嵌在这里 */
输入样例:
15
输出样例:
1307674368000
2.解题
解题方法有两种 有优劣之分
//1更改数据类型范围的方法 14分
// void Print_Factorial (const int N )
// {
// int n = N;
// long long sum = 1;
// int i;
// if(n<0||n>1000)
// {
// printf("Invalid input");
// }
// else
// for(i=n;i>0;i--)
// {
// sum *= i;
// }
// printf("%lld",