The first day of class 100!

xiaoxiao2021-03-17  186

Start formal class, I feel okay, this is the job of the teacher's first day, 100!, Spend a whole morning, put it up to be a memorable, I feel that the code is very written, the code is very simple, using iteration The time utility should be not bad, better than some of the online recursive.

The following is the original code:

Using system;

Namespace consoleApplication5 {class class1 {/ * This problem is high precision algorithm, often used for banks, can also be used to calculate a few hundred after PI * /

Static int [] Factorial (int N) // classification algorithm, using the number of one-dimensional groups to save {const INT ArrayNum = 200; // array dimension, if it is a first step, change this Int [] FAC = New int [arraynum]; // Result array int [] add = new int [arraynum]; // carry array for (int i = 0; i

For (int i = 0; I

For (int R = 1; r <= n; R ) // iteration start, ie 1 * 2 * 3 * .... n {for (int K = 1; k

Return FAC; // Return the result array}

Static void main (string [] args) {try {console.writeline ("Please enter 1-100!"); string temp = console.readline (); int n = int32.parse (temp); if (n <1 || n> 100) Throw new exception ("Not 1-100 Range");

int [] result = factorial (n);

// Reverse output int I = result.length-1; for (; i> = 0; I -) // Remove the array in front of 0 elements {IF (Result [i]! = 0) Break;} for i> = 0; I ---) // reverse output, ie 00321, output is 123 console.write ("{0}", Result [I]);}

Catch (Exception E) {Console.writeLine (E.MESSAGE);} Finally {Console.readLine ();

// End of the program

}}}

转载请注明原文地址:https://www.9cbs.com/read-129514.html

New Post(0)