bigdata.txt

来自「实现不超过100的数的阶乘!用数组实现打出的存储」· 文本 代码 · 共 86 行

TXT
86
字号
// jiecheng.cpp: implementation of the jiecheng class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "bigdata.h"
#include "jiecheng.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

jiecheng::jiecheng()
{

}

jiecheng::~jiecheng()
{

}

CString jiecheng::change()
{
	CString str,str1;
   long a[256],b,d;
   int m,i,j,r;
	//输入数字
	m=(int)log(n)*n/6+2;//估算需要占用的位数
	a[1]=1;
	for( i=2;i<=m;i++)
		a[i]=0;
	d=0;//存储超过6位后的进位
	for( i=2; i<=n;i++)
	{	for (j=1;j<=m;j++)
			{
				b=a[j]*i+d;     
				a[j]=b%1000000;   
				d=b/1000000;
			}
				
		if(d!=0)
				{
					a[j]=d;
					//m++;
				}

	}
		for (i=m ;i>=1;i--)
			if( a[i]==0)           
				continue;  
			else    
				{
					r=i;    
					break;
				}
	str1.Format("%d",a[r]);
    str=str+str1+" ";
    for(i=r-1;i>=1;i--)
    {
	 if (a[i]>99999)   
		{str1.Format("%d",a[i]); str=str+str1+" ";continue;}
     if  (a[i]>9999)   
		{str1.Format("%d",a[i]);str=str+"0"+str1+" "; continue;}
     if  (a[i]>999)  
		{str1.Format("%d",a[i]);str=str+"00"+str1+" "; continue;}
     if  (a[i]>99 )     
		{str1.Format("%d",a[i]);str=str+"000"+str1+" ";  continue;}
     if  (a[i]>9)      
		{str1.Format("%d",a[i]);str=str+"0000"+str1+" "; continue;}
     str1.Format("%d",a[i]);str=str+"00000"+str1+" ";
    }
	return str;
}

void jiecheng::GetData(int m)
{
   n=m;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?