I was asked to create an mxn factorial matrix. I created the matrix but how to do the factorial? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

8th May 2021, 9:20 AM
Osama Ghaleb
Osama Ghaleb - avatar
2 Answers
+ 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.
8th May 2021, 12:10 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 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
8th May 2021, 10:23 AM
YUGRAJ