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

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:


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