Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

USE C# // Algroithm for Big Factorial static void man(): 1. create unsigned integer array of 5000 elements. Example: const int size = 5000; uint[]

USE C#

// Algroithm for Big Factorial static void man(): 1. create unsigned integer array of 5000 elements. Example: const int size = 5000; uint[] factorial = new uint[size]; 2. create an variable for store last element index in array to know the most left element whith value 3. using do...while loop for enter interact procedure do { - set array elements to 0. - ask the user to enter number for compute factorial or -1 to exit program. - take the number to compute factorial by passing array and number to "ComputeFactorial" mehtod. // ComputeFactorial(?, ?, ?); - Display result to screen by call "Display" method. } while(number equal or not to -1)

// Compute Factorial Method /* Methed Name: ComputeFactorial

methed description: computing factorial numbers and set up 6 digits number for each element in passing factorial array. Parameters: 1. unsigned interger array, which stor the result of factorial number (passing by refernce) // ref type[] name; 2. integer variable of number for store last element indext in result array that is the most letf element with value. (passing by refernce, for void method) Local variable: 2 integer variable for two loop index. integer variable for carry. unsigned type of integer variable for result. integer variable for last_element (only for return method). return value: none.

*/ static void ComputerFactorial( ? , ? , ?) { //local variables declare here first. - set first element in result array to 1. (index 1 or index N-1) - set last_element index variable to 1. - set carray to 0; - apply simple factorial formula, N! = 1 * 2 * 3 * 4...... * N-1. - two loops to control the computation sequence outer loop: for how many mutiply operation for compute factorial number (index should begin with 2) { inter loop: compute factorial number and store the result into factorial array { - using factorial formula to compute one element result = element of array * outer loop index value + (uint) carry; - you need to check the result for 6 digits or beigger (it is check for carry or not) if(result > 999999) { -you need to compute carray. -compute correct value to store in the current element of array } else { -store result into the current element of array. -set the carry to 0; } } if you still have carry value (carry is greater then 0) { -increment last_element index by 1. -store carry to last_element in factorial array; -set carry to 0; } decrement last_element by 1. } }

// Compute Factorial mehtod with return last_element index static int ComputeFactorial( ?, ? ) //must return last element of index in reasult array //that is the most left element with value. { declare last_element variable; /* same as above method */ return last _element; }

// Display Method /* Method Name: Display Method description: Display the resutl to the screen for big factorial number.

Parameters List: unsigned integer array for big factorial number integer variable for last element indext of factorial array integer number for size of array (this is option)

local variables: array index for factorial array. integer variable count for counting 60 digits each line */ static void Display( ? , ? ) { declare local variables here set count to 0. Write the message "The big factorial of N is : " loop set index it to last_element, then check i greater than equal to 0. { if(index i equal to last_element) //taking care the leading space in first //element of factial array { if(array of index i value not equal to 0) { -check value in array element i has how may digits if(value in factorial[i] is less than 10)//this element only has 1 digits value Write 5 space characteras befor the value to screen. else if(value in factorial[i] is less than 100)//this element only has 1 digits value Write 4 space characteras befor the value to screen. else if(value in factorial[i] is less than 1000)//this element only has 1 digits value Write 3 space characteras befor the value to screen. else if(value in factorial[i] is less than 10000)//this element only has 1 digits value Write 2 space characteras befor the value to screen. else if(value in factorial[i] is less than 100000)//this element only has 1 digits value Write 1 space characteras befor the value to screen. else Write the value in factorial[i] to screen } } else { //taking care the leding zero in each element of factirial array for write to screen if(value in factorial[i] equal to 0) Write 6 zero characteras to screen else if(value in factorial[i] less then 10) Write 5 zero characteras to screen else if(value in factorial[i] less then 100) Write 4 zero characteras to screen else if(value in factorial[i] less then 1000) Write 3 zero characteras to screen else if(value in factorial[i] less then 10000) Write 2 zero characteras to screen else if(value in factorial[i] less then 100000) Write 1 zero characteras to screen } increment count by 6 Write " " to screnn (optional)// it is for readablilty if(count value equal to 60) { Write " " to screen. reset the count to 0. } decrement index of array i by 1. } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions