Question

In: Computer Science

Write a factorial C++ program where n=10,000,000

Write a factorial C++ program where n=10,000,000

Solutions

Expert Solution

Save the following program in file factorial.cpp


#include<iostream>
using namespace std;


#define MAXSIZE 500000 // size of the array to hold intermidiate multiplication results

int mult(int num, int res[], int res_size);

// Function to find factorial
void findFfactorial(int num) {
int res[MAXSIZE];
res[0] = 1;
int res_size = 1;

for (int i=2; i<=num; i++)
res_size = mult(i, res, res_size);

cout << "Factorial of the number is: ";
for (int i=res_size-1; i>=0; i--)
cout << res[i];
}

// function to find result of progressive multiplications in each step
int mult(int num, int res[], int res_size) {
int carry = 0;
for (int i=0; i<res_size; i++) {
int prod = res[i] * num + carry;
res[i] = prod % 10;
carry = prod/10;
}
while (carry){
res[res_size] = carry%10;
carry = carry/10;
res_size++;
}
return res_size;
}


int main() {
//findFfactorial(10000000);

findFfactorial(10);
return 0;
}

The factorial of supplied number 10000000 will give very long output,, which is not possible to show here. hence I ran the program with small sample value 10, to show you the result here.

Output:

Factorial of the number is: 3628800

You can run the program in your local machine to see the output.


Related Solutions

Write a factorial C++ program where n=10,000,000
Write a factorial C++ program where n=10,000,000
Write down the C++ Program To Find Factorial.
Write a function, which accepts an integer value as an argument, finds the factorial of that integer value, and then returns the factorial value to the main program. Write a main program that will call the function by passing an integer value and print the factorial value returned by the function. 
In C++, write a program that uses array to calculate the factorial of a reasonable large...
In C++, write a program that uses array to calculate the factorial of a reasonable large number (say, up to 2,000).
In C++. Write a program that uses array to calculate the factorial of a reasonable large...
In C++. Write a program that uses array to calculate the factorial of a reasonable large number (say, up to 2,000).  
(1) Write a simple Lisp function factorial1 to computee factorial number of n recursivaly (where n...
(1) Write a simple Lisp function factorial1 to computee factorial number of n recursivaly (where n is an int >= 0). (2) Write a Lisp function factorial2 to computee factorial number of n (where n is an int >=0) recursivaly with a global variable (e.g., a list, an array, or a hash tble) to save the result to be used later (memorization) to compute next factorial number. Run the program with test case. For your test run, the following cases:...
Write a recursive function to calculate and return factorial of a given number 'n'. in C...
Write a recursive function to calculate and return factorial of a given number 'n'. in C progrmaining
Write a program in C or C++ that takes a number series of size n (n...
Write a program in C or C++ that takes a number series of size n (n integers) as input from the user, push all the numbers to the stack, and reverse the stack using recursion. Please note that this is not simply popping and printing the numbers, but the program should manipulate the stack to have the numbers stored in reverse order. In addition to the provided header file, the students can use the following function to print the content...
Write a c program to calculate the factorial of a number using recursion    [8] Question five...
Write a c program to calculate the factorial of a number using recursion    [8] Question five Write a stack algorithm to POP an item                                                         [6] What does FRONT and REAR signify in a queue?                                                                 [6] Write an algorithm for a dequeue operation                                                                       [8]
Write a recursive function to implement the Factorial of n (n!). In the main, let the...
Write a recursive function to implement the Factorial of n (n!). In the main, let the user input a positive integer and call your function to return the result.
Write a program (O(n), where n is the number of words) that takes as input a...
Write a program (O(n), where n is the number of words) that takes as input a set of words and returns groups of anagrams for those words. Complete your code here Do not change anything in the test file. CPP File: #include #include #include #include using namespace std; vector> findAnagrams(const vector& dict); vector> findAnagrams(const vector& dict) { // Your code here... } Test File: #include #include #include #include using namespace std; vector> findAnagrams(const vector& dict); int main() { vector word_list...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT