1088的阶乘是多少?
- 内容介绍
- 文章标签
- 相关推荐
本文共计366个文字,预计阅读时间需要2分钟。
问题描述 + Description + 请求N!(N=10000)!输出10007取余的结果。输入 + 输入 + 每行输入一个整数n,遇到-1结束。输出 + 输出 + 每行输出一个整数,为对应n的运算结果。示例输入 + Sample Input + 1 + 2 + -1 + 示例输出 + Sample Output + 1 + 2 + Source ericxie + 源代码
问题描述
Description
请求N!(N<=10000),输出结果对10007取余
输入
每行一个整数n,遇到-1结束。
输出
每行一个整数,为对应n的运算结果。
Sample Input
1
2
-1
Sample Output
1
2
Source
ericxie
源代码及详细注释
我们要求的是,N的阶乘,再对10007取余
#include <stdio.h>int main()
{
int n,i;
while(scanf("%d",&n)&&n!=-1)
{
int s=1;
for(i=1;i<=n;i++)//求阶乘,并且每步取余
{
s=(s*i)%10007;
}
printf("%d\n",s);
}
return 0;
}
上面的代码是对的,下面的代码是错的,请仔细比对下,为什么,可以在评论区里写下你的解答哦
#include <stdio.h>int main()
{
int n,i,s=1;
while(scanf("%d",&n)&&n!=-1)
{
for(i=1;i<=n;i++)//求阶乘,并且每步取余
{
s=(s*i)%10007;
}
printf("%d\n",s);
}
return 0;
}
写于2021年8月4日23:25分。
本文共计366个文字,预计阅读时间需要2分钟。
问题描述 + Description + 请求N!(N=10000)!输出10007取余的结果。输入 + 输入 + 每行输入一个整数n,遇到-1结束。输出 + 输出 + 每行输出一个整数,为对应n的运算结果。示例输入 + Sample Input + 1 + 2 + -1 + 示例输出 + Sample Output + 1 + 2 + Source ericxie + 源代码
问题描述
Description
请求N!(N<=10000),输出结果对10007取余
输入
每行一个整数n,遇到-1结束。
输出
每行一个整数,为对应n的运算结果。
Sample Input
1
2
-1
Sample Output
1
2
Source
ericxie
源代码及详细注释
我们要求的是,N的阶乘,再对10007取余
#include <stdio.h>int main()
{
int n,i;
while(scanf("%d",&n)&&n!=-1)
{
int s=1;
for(i=1;i<=n;i++)//求阶乘,并且每步取余
{
s=(s*i)%10007;
}
printf("%d\n",s);
}
return 0;
}
上面的代码是对的,下面的代码是错的,请仔细比对下,为什么,可以在评论区里写下你的解答哦
#include <stdio.h>int main()
{
int n,i,s=1;
while(scanf("%d",&n)&&n!=-1)
{
for(i=1;i<=n;i++)//求阶乘,并且每步取余
{
s=(s*i)%10007;
}
printf("%d\n",s);
}
return 0;
}
写于2021年8月4日23:25分。

