In: Computer Science
Write a factorial C++ program where n=10,000,000
ANSWER: Here I am giving you the code and output since there are many pages output so I am not able to give all output images .Please run this code on your personal laptop with personal compiler like codeblocks and it will take time to give you the output about 10-15 minutes so wait unitill output not appeared.Dont use the online compiler to run this code .
CODE:
#include<iostream>
using namespace std;
#define MAX 500000 // it will be the size of the array
int multiplication(int x, int res[], int result_size);
void factorialOfNumber(int n)
{
int res[MAX];
res[0] = 1;
int result_size = 1;
for (int x=2; x<=n; x++)
result_size = multiplication(x,
res, result_size);
cout << "factorial of given number is
\n";
for (int i=result_size-1; i>=0; i--)
cout << res[i];
}
int multiplication(int x, int res[], int result_size)
{
int carry = 0;
for (int i=0; i<result_size; i++)
{
int prod = res[i] * x +
carry;
res[i] = prod % 10;
carry = prod/10;
}
while (carry)
{
res[result_size] = carry%10;
carry = carry/10;
result_size++;
}
return result_size;
}
int main()
{
factorialOfNumber(10000000);// Your given number
return 0;
}
output: