首页 > 其他 > 详细

可怕的阶乘

时间:2015-05-05 19:43:01      阅读:279      评论:0      收藏:0      [点我收藏+]
<span style="font-family: Arial, Helvetica, sans-serif;">#include <stdlib.h></span>
#include <stdio.h>
#include <string.h>
#include "oj.h"

void CalcNN(int n, char *pOut)
{
	if(0 == n || 1 == n)
	{
		pOut[0] = 1;
		pOut[1] = '\0';

	}
	else
	{
		int product[1000] ;
		memset(product, 0, sizeof(int) * 1000);

		int temp = 0;	//存储临时变量
		int carry = 0; //进位标志
		int len = 1;    //数组长度

		product[0] = 1;

		for ( int i = 2; i <= n; ++i)
		{
			carry = 0;
			for (int j = 0; j < len; ++ j)
			{
				temp = product[j] * i + carry;
				product[j] = temp % 10;
				carry = temp /10;
			}
			while(carry != 0)
			{
				product[len] = carry % 10;
				carry /= 10;
				len ++;
			}
		}

		for (int i = 0; i < len; ++i)//逆序存储
		{
			pOut[i] = product[len - i -1] + '0';
		}
		pOut[len] = '\0';

	}


	return;
}

可怕的阶乘

原文:http://blog.csdn.net/xiaohanstu/article/details/45504363

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