Question
// Here's what I have so far but I'm wondering about the leading zeros and how to write the code properly based on the instructions?
// Here's what I have so far but I'm wondering about the leading zeros and how to write the code properly based on the instructions?
using System;
class Program { static void Main() { const int size = 5000; uint[] factorial = new uint[size]; int mostLeft = 0;
do { // Reset the array to 0 Array.Clear(factorial, 0, size);
Console.Write("Enter a number to compute its factorial, or -1 to exit: "); int number = int.Parse(Console.ReadLine());
if (number == -1) { break; }
ComputeFactorial(ref factorial, ref mostLeft, number); Display(factorial, mostLeft); } while (true); }
static void ComputeFactorial(ref uint[] factorial, ref int mostLeft, int number) { factorial[0] = 1; mostLeft = 0;
for (int i = 2; i
for (int j = 0; j
if (carry > 0) { mostLeft++; factorial[mostLeft] = carry; } } }
static void Display(uint[] factorial, int mostLeft) { Console.Write(factorial[mostLeft]);
for (int i = mostLeft - 1; i >= 0; i--) { Console.Write(factorial[i].ToString("D6")); }
Console.WriteLine(); } }
Develop a program to compute N! using unsigned integer type of array to store; for a N from 1 to 99,999,999. The result can be a very long number. For example, the factorial of 50 is: 30,414,093,201,713,378,043,612,608,166,064,768,844,377,641,568,960,512,000,000,000,000 In the main method, you ask user to enter factorial number N to compute and create unsigned integer type of an array with 5000 elements to store result of factorial number. Pass an array to the function by reference so that when execution returns from the function and an array will contain final factorials number. The function will compute N! and store into array with a maximum 6 digits per element. In order to solve this problem, you will initialize the first element of array that it contains 1 ! Before computing the factorial requested by the user. The factorial of zero and the factorial of one is one (2! is 2,3! is 6,4 ! is 24 ...etc). You need to design how you want to store number into array from 0 to 5000 element or 5000 to 0 element, which is very important when you design your display method. Write a method to compute the factorial of a number using the algorithm described in class. This should be as efficient as possible. You should store a maximum 6 digits per element and perform computation for large factorials. Write a method to display the factorial you computed. As you print the value in each element of array you will need to fill in leading zeros by printing character zeros if the digits in an element of the array (except for the beginning of the number) contains leading zeros. Do not print commas in the numbers as shown above. You can only display 60 characters per line. Print to the screen the factorial number you were computing, the number of digits in the value, and print all the digits in the number that was computed. After you have printed the results, as the user to input the next integer number to be used to compute a factorial. Terminate the program when the user enters a negative number. You should find out what is biggest factorial number that your program can compute and how long to finished (time)? (Wire the answer of this question in the comment section at the beginning of the program)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started