+ 1
I was asked to create an mxn factorial matrix. I created the matrix but how to do the factorial?
Question: Create an mxn (user-defined) factorial matrix using the Rand () function. Make sure the Rand () function is not repeated. The factorial must be computed in a separate function. The factorial matrices can be seen below: (rand () variable range is 0-10) 4! 5! 3! 3! 1! 2! 9! 7! Calculate the factorials for the final display on the screen. You have permission to specify any range of random variables. https://code.sololearn.com/cXC3G5L7cczh/?ref=app
2 odpowiedzi
+ 2
//pseudo code :
int fact(int n){
returns n!
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
matrix[i][j] = fact(randomNumberFrom0to10);
A more better approach would be to make an array of size 11 and store factorials from 0 to 10 in it as if n*m>11 then definitely it will be calculating factorial of same number(s) multiple times.
+ 1
For factorial create a different function which takes a number as argument and return factorial
Factorial of a number is calculated as
5! =5*4*3*2*1