How do I write a for loop that finds the product of natural numbers from 1 to 50.
i.e. 1x2x3x4...x50

3 comentarios

Stephen23
Stephen23 el 23 de Abr. de 2019
Editada: Stephen23 el 23 de Abr. de 2019
@Cebolenkosi Mandlanti : what have you tried so far?
How accurate does the answer need to be?
Stephen23
Stephen23 el 23 de Abr. de 2019
Cebolenkosi Mandlanti's "Answer" moved here:
Not too accurate, I just want know how do I put it together.
Stephen23
Stephen23 el 23 de Abr. de 2019
Well, it is not very hard to multiply values using a loop, so I presume that you must have tried something in the twenty-three minutes since you wrote your question. Please show us what you have tried so far.

Iniciar sesión para comentar.

Respuestas (1)

Ravi Chaitanya
Ravi Chaitanya el 29 de Dic. de 2022

0 votos

Hello Cebolenkosi,
As per my understanding, you want to multiply numbers from 1 to 50 using a for loop.
Below is the code snippet for the same:
product = 1;
for num = 1:50
product=product*num;
end
disp(product);
Please refer to the MathWorks documentation on Loops and conditional statements here to know more.
Thanks!

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 23 de Abr. de 2019

Respondida:

el 29 de Dic. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by