首页 > 其他 > 详细

hlg2019大数阶乘

时间:2014-02-07 09:38:39      阅读:443      评论:0      收藏:0      [点我收藏+]
n! problem II
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 38(22 users) Total Accepted: 21(17 users) Rating:bubuko.com,布布扣 Special Judge: No
Description
求阶乘看起来是一个很简单的问题,现在我们要计算一个不超过100的整数的阶乘。
Input
本题有多组测试数据,对于每组数据输入一个非负整数n(n不大于100),输入处理到文件结束。
Output
输出n的阶乘并换行。
Sample Input

1

2

3

 

Sample Output

1

2

6

 

Source
杨和禹求职记
Author

首先认真审题,此题涉及到大数运算,具体代码如下:

#include<stdio.h>

#include<string.h>

int str[2000];

int main() {     int n,p,j;    

while(scanf("%d",&n)!=EOF){       

  memset(str,0,sizeof(str));        

str[0]=1;        

for(int i=2;i<=n;i++){            

p=0;             for(j=0;j<2000;j++){                

int s=str[j]*i+p;                

str[j]=s%10;                

p=s/10;             }        

}        

for(j=1999;j>=0;j--)            

if(str[j]!=0) break;        

for(int i=j;i>=0;i--) printf("%d",str[i]);        

printf("\n");

    }   

  return 0; }

hlg2019大数阶乘

原文:http://www.cnblogs.com/lxb1243816632/p/3539052.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!