C++_阶乘

// 100!.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include 
#include 
#include 
using namespace std;

vector g_iResult;
void Factorial(int n)
{
	if (g_iResult.size() == 0)
	{
		g_iResult.push_back(1);
	}
	if (n == 1 || n == 0)
	{
		return;
	}
	else
	{
		int *element = g_iResult.data();
		for (int i = 0; i < g_iResult.size(); i ++)
		{
			*element = *element * n;
			element++;
		}
		if (g_iResult.back() > 1000)
		{
			int small = g_iResult.back() % 1000;
			int big  = g_iResult.back() / 1000;
			g_iResult.pop_back();
			g_iResult.push_back(small);
			g_iResult.push_back(big);
		}
		element = g_iResult.data();
		for (int i = 0; i < g_iResult.size(); i ++)
		{
			if (*element > 1000)
			{
				int big = *element / 1000;
				*element = *element % 1000;
				element ++;
				*element = *element + big;
			}
			else
			{
				element ++;
			}
		}
		Factorial( n - 1 );
	}
}

int _tmain(int argc, _TCHAR* argv[])
{
	Factorial(1000);//求20的阶乘
	cout<= 0; i--)
	{
		printf("%03d", g_iResult.at(i));
		//cout<


你可能感兴趣的:(C++,控制台)