Created
May 25, 2011 14:49
-
-
Save kor-trickster/991108 to your computer and use it in GitHub Desktop.
Factorial Function (MFC - String version)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define CUT_LENGTH ?? | |
CString Fact(int end){ | |
CString num1 = _T("1"); | |
CString num2 = _T(""); | |
CString num3 = _T(""); | |
for(int i = 1; i <= end; ++i){ | |
unsigned int tmp = 0; | |
num2 = _T(""); | |
num3 = _T(""); | |
while(num1.GetLength() > CUT_LENGTH){ | |
num2 = num1.Right(CUT_LENGTH); | |
num1 = num1.Left(num1.GetLength() - CUT_LENGTH); | |
unsigned int x = _tstoi(num2) * i; | |
num2.Format("%u", x + tmp); | |
tmp = 0; | |
if(num2.GetLength() > CUT_LENGTH){ | |
tmp = _tstoi(num2.Left(num2.GetLength() - CUT_LENGTH)); | |
num2 = num2.Right(CUT_LENGTH); | |
} | |
else if(num2.GetLength() < CUT_LENGTH){ | |
while(num2.GetLength() < CUT_LENGTH){ | |
num2 = _T("0") + num2; | |
} | |
} | |
num3.SetString(num2 + num3); | |
} | |
unsigned int y = _tstoi(num1) * i; | |
num1.Format("%u", y + tmp); | |
tmp = 0; | |
num1 = num1 + num3; | |
} | |
return num1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment