6-10 阶乘计算升级版 (20 分)
发布日期:2021-06-29 22:19:13 浏览次数:2 分类:技术文章

本文共 668 字,大约阅读时间需要 2 分钟。

本题要求实现一个打印非负整数阶乘的函数。 函数接口定义: 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

void Print_Factorial ( const int N )

{
int k=1,n=0,temp,num[1000000]={0},i,j;
num[0]=1;//n!=123*·····n!;顾刚开始的初值都为 1;
if(N>=0&&N<=1000)
{
for(i=2;i<=N;i++)
{
for(j=0;j<k;j++)
{
temp=num[j]*i+n;
num[j]=temp%10;
n=temp/10;
}
while(n!=0)
{
num[k]=n%10;
n=n/10;
k++;
}
}
for(i=k-1;i>=0;i–)
{
printf("%d",num[i]);
}
}
else {
printf(“Invalid input”);
}
}
*

转载地址:https://dingshijie.blog.csdn.net/article/details/86848755 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:7-78 阅览室 (20 分)
下一篇:习题4-6 水仙花数 (20 分)

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月14日 12时35分56秒