How can I use conditional operators to improve my code?

1 visualización (últimos 30 días)
zachary owen
zachary owen el 13 de Oct. de 2019
Comentada: Daniel M el 13 de Oct. de 2019
Hello, i'm new to Matlab and I was wondering if someone could help me find the fault in my code. I've written the script below, and my code is posted below that. My issue is that my integer values in the command window display horizontally rather than vertically even after i've transposed it. I'm not concerned with the sum of the 4 factorials portion of the script just yet. Thanks!
This is what i'm trying to accomplish:
For N<12, generate a script that displays n!, n = 1,2,.....,N and the sum of these factorials as shown for N = 4.
Enter an integer < 12: 4
For n = 1, 1! = 1
For n = 2, 2! = 2
For n = 3, 3! = 6
For n = 4, 4! = 24
The sum of these 4 factorials = 33
Where the value of 4 was enetered by the user.

Respuesta aceptada

Daniel M
Daniel M el 13 de Oct. de 2019
N = [1:n];
s = [N;N;factorial(N)];
fprintf('For N = %d, %d! = %d\n',s);

Más respuestas (0)

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by