C语言编程题—求100!

xinxinghuoliaoyuan 2010-04-03 12:02:38
使用C语言编出可以计算100!的程序。
大家加油哦!
...全文
433 42 打赏 收藏 转发到动态 举报
写回复
用AI写文章
42 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinxinghuoliaoyuan 2010-04-06
  • 打赏
  • 举报
回复
#include <stdio.h>
void main()
{
int x,i,j,k,a[200],b[200]={1};
scanf("%d",&x);
for(i=0;i<x;i++)
a[i]=i+1;
for(i=0;i<x;i++)
{
for(j=0;j<200;j++)
b[j]=b[j]*a[i];
for(j=0;j<199;j++)
{
b[j+1]=b[j+1]+b[j]/10;
b[j]=b[j]%10;
}
}
for(i=199;i>=0;i--)
{
if(b[i]>0)
break;
}
k=i+1;
printf("k=%d\n",k);
for(j=k-1;j>=0;j--)
printf("%d",b[j]);
printf("\n\n");
}我写的结果是933262154439441526816992388562667004907
159682643816214685929638952175999932299
156089414639761565182862536979208272237
582511852109168640000000000000000000000
starboy520 2010-04-03
  • 打赏
  • 举报
回复
lz 用python 吧,^_^
AAA20090987 2010-04-03
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;

const int MAX = 100000;
const int SIZE = 40000/5 + 2;
void Factorial(int *arr, int n);

int main()
{
int arr[SIZE];
int n;
while(cin >> n)
{
memset(arr, 0, sizeof(arr));
Factorial(arr, n);
}
return 0;
}

void Factorial(int *arr, int n)
{
int i, j, pos;
pos = SIZE - 1;
arr[SIZE-1] = 1;
for(i=2;i<=n;i++)
{
for(j=SIZE-1;j>=pos;j--)
arr[j] *= i;
for(j=SIZE-1;j>=pos;j--)
{
if(arr[j] > MAX)
{
if(j == pos)
pos--;
arr[j-1] = arr[j-1] + arr[j]/MAX;
arr[j] %= MAX;
}
}
}
i = 0;
printf("%d", arr[pos++]);
for(;pos<SIZE;pos++)
printf("%05d", arr[pos]);
printf("\n");
}
柯本 2010-04-03
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 t0ols 的回复:]
谁能告诉我 100! 是多少 100亿吗?
[/Quote]
我在17楼的结果你看一下
fengqiang6863 2010-04-03
  • 打赏
  • 举报
回复
lz,接分。。
风子II 2010-04-03
  • 打赏
  • 举报
回复
接分~
lovesi3344 2010-04-03
  • 打赏
  • 举报
回复
被楼主当猴耍了 悲剧
lovesi3344 2010-04-03
  • 打赏
  • 举报
回复
#include<stdio.h>
int main()
{
int n;
while (scanf("%d",&n)!=EOF)
{
long v[10000]={1},i=2,a=1,u=0,h=0;
for (i=2;i<=n;i++)
for (u=0,a=0;a<=h;a++)
{
u+=v[a]*i;
v[a]=u%10000;
u/=10000;
if(h==a&&u) h++;
}
printf("%d",v[h]);
while (--h>=0)
printf("%04d",v[h]);
printf("\n");
}
return 0;
}
jbz001 2010-04-03
  • 打赏
  • 举报
回复
我是来看大家怎么写的~!
yzx714 2010-04-03
  • 打赏
  • 举报
回复
楼主在网上去搜云中飞燕的NB代码吧…………
或者还是用个大数库吧,我一直用GNU的那个
sbdt123 2010-04-03
  • 打赏
  • 举报
回复
请回复的好好运行后再回复,别只是粘帖
andychinajj 2010-04-03
  • 打赏
  • 举报
回复
分!!!!!
T0Ols 2010-04-03
  • 打赏
  • 举报
回复
谁能告诉我 100! 是多少 100亿吗?
lovesi3344 2010-04-03
  • 打赏
  • 举报
回复

你输入100 不就得出结果了么

楼主 我是1楼 快给我分吧 我写程序很不容易 你居然说我的程序不能运行 你用啥编译器
如果不行 可以#include<conio.h> 然后在return 0; 之前加上一句 getch();

我这程序算任何阶乘都行


[Quote=引用 6 楼 xinxinghuoliaoyuan 的回复:]
拜托啊!都没运行出来啊!
[/Quote]
柯本 2010-04-03
  • 打赏
  • 举报
回复
结果为:
933262154439441526816992388562667004907
159682643816214685929638952175999932299
156089414639761565182862536979208272237
582511852109168640000000000000000000000
柯本 2010-04-03
  • 打赏
  • 举报
回复
试试我的大运算库:
http://download.csdn.net/source/2198401
程序为:
#include <iostream>
#include "BigIntegerLibrary.h"
using namespace std;

int main()
{
int i;
BigInteger n(1);
for(i=1;i<100;i++)
n=n*i;
cout <<n<< endl;
}
Rommel0226 2010-04-03
  • 打赏
  • 举报
回复
int sum=1
for(int i=100;i>0;i--)
{
sum *=i;
}
return sum;
scx44 2010-04-03
  • 打赏
  • 举报
回复
知道雨中飞燕吗?
1000!的阶乘他只用了8行代码就写出来了。

我闺女莫依也可以滴。
zbychhaozeng 2010-04-03
  • 打赏
  • 举报
回复
顶一楼!
落随风 2010-04-03
  • 打赏
  • 举报
回复
接分~~~~~~
加载更多回复(22)

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧