Double fact (int n); Function declaration/* */
Int main (void)
{
int i;
Double sum;
sum=0;
for(i=1; i<=100; I++)
Sum=sum + fact (I); I call fact/* (I) o! Repeat, a total of 100 times */
Printf (" 1! + 2! +... + 100!=% d \ n ", sum);/* output in index form */
return 0;
}
/* define o n! The function of */
Double fact (int n)
{
int i;
Double the result;/* deposit class values in the variable result */
Result=1; The result of the initial value is 1/* buy class */
for(i=1; i<=n; I++)/* loop n times, calculate n! */
Result=result * I;
return result;/* */send the results back to the main function
}
CodePudding user response:
Only supplies the reference: 100!!!# include & lt; Iostream>
#include
#include
using namespace std;
The inline int the COMPARE (string str1, string str2) {//return equal 0, is greater than the return 1, less than the return 1
If (str1. The size () & gt; Str2. The size ()) return 1;//the length of the long integer greater than the length of the integer
Else if (str1. The size () & lt; Str2. The size ()) return 1;
The else pare said return str1.com (str2);//if equal length, head to tail according to the comparison of
}
String PLUS (string number1, string number2) {
int i;
Int length1=number1. The size ();
Int length2=number2. The size ();
The string result="";
Reverse (number1. The begin (), number1. The end ());
Reverse (number2. The begin (), number2. The end ());
for(i=0; I & lt; Length1 & amp; & I & lt; Length2. I++) {
Char c=(char) (number1 number2 [I] + [I] - 48).
Result=result + c;
}
While (I & lt; Length1) {
Result=result + number1 [I];
+ + I;
}
While (I & lt; Length2) {
Result=result + number2 [I];
+ + I;
}
Int carry=0;
for(i=0; I & lt; (int) result. The size (); + + I) {
Int [I] value=https://bbs.csdn.net/topics/result - 48 + carry;
The result [I]=(char) (value % 10 + 48);
Carry=value/10;
}
If (carry!=0) {
Result=result + (char) + 48 (carry);
}
For (I=result. The size () - 1; I & gt;=0; I -) {
If (result [I]!='0') break;
}
Result=result. The substr (0, I + 1);
Reverse (result. The begin (), the result. The end ());
If (result. The length ()==0) result="0";
return result;
}
String MULTIPLY (string number1, string number2) {
int i, j;
Int * iresult;
Int length1=number1. The size ();
Int length2=number2. The size ();
The string result="";
Reverse (number1. The begin (), number1. The end ());
Reverse (number2. The begin (), number2. The end ());
Iresult=(int *) malloc (sizeof (int) * (length1 + length2 + 1));
Memset (iresult, 0, sizeof (int) * (length1 + length2 + 1));
for(i=0; I & lt; Length1; I++) {
For (j=0; J & lt; Length2. J++) {
Iresult [I + j] +=((number1 [I] - 48) * (number2 [j] - 48));
}
}
Int carry=0;
for(i=0; I & lt; Length1 + length2; I++) {
The int value=https://bbs.csdn.net/topics/iresult [I] + carry;
Iresult=[I] value % 10;
Carry=value/10;
}
For (I=length1 + length2-1; I & gt;=0; I -) {
If (iresult [I]!=0) break;
}
For (; I & gt;=0; I -) {
Result=result + (char) (iresult [I] + 48);
}
Free (iresult);
If (result=="") result=" 0 ";
return result;
}
The string of the factorial (string n) {
String temp="1";
The string I;
For (I="1"; COMPARE (I, n) & lt;=0; I=PLUS (I, "1")) {
Temp=MULTIPLY (temp, I);
}
Return temp.
}
Int main (void) {
Cout & lt;return 0;
}
//93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
//