factorial

How to get a JavaScript factorial programs' loop to show the working used?

不羁的心 提交于 2020-12-12 05:38:46
问题 Hello there I have been challenged to write a program in JavaScript despite not really knowing much about it that asks the user for a number and then calculates the factorial of that number. I used already asked questions and managed to get the calculation to work but couldn't get the required output. I have to get it in the following output without using any fancy libraries or extra variables/arrays (which I can't think of how to do) : (assuming user input is 5): The factorial of 5 is 5*4*3

How to get a JavaScript factorial programs' loop to show the working used?

感情迁移 提交于 2020-12-12 05:38:27
问题 Hello there I have been challenged to write a program in JavaScript despite not really knowing much about it that asks the user for a number and then calculates the factorial of that number. I used already asked questions and managed to get the calculation to work but couldn't get the required output. I have to get it in the following output without using any fancy libraries or extra variables/arrays (which I can't think of how to do) : (assuming user input is 5): The factorial of 5 is 5*4*3

Is there a special formula for permutation

有些话、适合烂在心里 提交于 2020-07-23 09:26:46
问题 Who can help me out with a QBASIC CODE to find the permutation of a given number. I'd really appreciate. I've tried writing some codes but it's not giving the required answer. 回答1: If by permutation you mean the factorial then the following is the code that you need. It will get an integer and compute its factorial. DECLARE FUNCTION Factorial (n) FUNCTION Factorial (n) IF n = 0 THEN Factorial = 1 ELSE Factorial = n * Factorial(n - 1) END IF END FUNCTION INPUT "PLEASE ENTER AN INTEGER", n

Is there a special formula for permutation

淺唱寂寞╮ 提交于 2020-07-23 09:24:08
问题 Who can help me out with a QBASIC CODE to find the permutation of a given number. I'd really appreciate. I've tried writing some codes but it's not giving the required answer. 回答1: If by permutation you mean the factorial then the following is the code that you need. It will get an integer and compute its factorial. DECLARE FUNCTION Factorial (n) FUNCTION Factorial (n) IF n = 0 THEN Factorial = 1 ELSE Factorial = n * Factorial(n - 1) END IF END FUNCTION INPUT "PLEASE ENTER AN INTEGER", n

Is there a special formula for permutation

前提是你 提交于 2020-07-23 09:23:25
问题 Who can help me out with a QBASIC CODE to find the permutation of a given number. I'd really appreciate. I've tried writing some codes but it's not giving the required answer. 回答1: If by permutation you mean the factorial then the following is the code that you need. It will get an integer and compute its factorial. DECLARE FUNCTION Factorial (n) FUNCTION Factorial (n) IF n = 0 THEN Factorial = 1 ELSE Factorial = n * Factorial(n - 1) END IF END FUNCTION INPUT "PLEASE ENTER AN INTEGER", n

Factorial of a matrix elementwise with Numpy

拥有回忆 提交于 2020-06-27 07:36:32
问题 I'd like to know how to calculate the factorial of a matrix elementwise. For example, import numpy as np mat = np.array([[1,2,3],[2,3,4]]) np.the_function_i_want(mat) would give a matrix mat2 such that mat2[i,j] = mat[i,j]! . I've tried something like np.fromfunction(lambda i,j: np.math.factorial(mat[i,j])) but it passes the entire matrix as argument for np.math.factorial . I've also tried to use scipy.vectorize but for matrices larger than 10x10 I get an error. This is the code I wrote:

Find the number of digit(s) of the factorial of an integer in a certain base

不羁的心 提交于 2020-05-23 11:37:47
问题 My solution was pretty fast but not enough. I need more faster. How can I reduce my time? Input Number: n (0 ≤ n ≤ 1000000) Base should be: base (2 ≤ base ≤ 1000) Input 5! in 10 base. Output is: 3 Input 22! in 3 base. Output is: 45 Time Limit: 2 second(s), and Memory Limit: 32 MB Here is my code in c language: #include<stdio.h> #include<math.h> int factorialDigitExtended ( int n, int base ) { double x = 0; for ( int i = 1; i <= n; i++ ) { x += log10 ( i ) / log10(base); } int res = ( (int) x

Issue with large number [duplicate]

夙愿已清 提交于 2020-05-15 08:22:32
问题 This question already has answers here : Counting trailing zeros of numbers resulted from factorial (10 answers) Closed last month . I'm trying to count the number of trailing zero with a factorial. e.g 4! = 24 So you retrieve 0. 9! = 362880 So you retrieve 1. 10! = 9! x 10 = 3628800 So you retrieve 2. 11! = 10! x 11 = 3.99168E7 So you retrieve 2. static double factorial(double n) { double f = 1; for(int i = 1 ; i <= n ; i++) { f *= i; } return f; } static int numberOfZeros(double f) { int

R: How can I calculate large numbers in n-choose-k? [duplicate]

こ雲淡風輕ζ 提交于 2020-05-13 04:13:48
问题 This question already has answers here : How would you program Pascal's triangle in R? (2 answers) How to work with large numbers in R? (1 answer) Closed 3 years ago . For a class assignment, I need to create a function that calculates n Choose k. I did just that, and it works fine with small numbers (e.g. 6 choose 2), but I'm supposed to get it work with 200 choose 50, where it naturally doesn't. The answer is too large and R outputs NaN or Inf, saying: > q5(200, 50) [1] "NaN" Warning