The for loop.

조회 수: 9 (최근 30일)
Cebolenkosi Mandlanti
Cebolenkosi Mandlanti 2019년 4월 23일
답변: Ravi Chaitanya 2022년 12월 29일
How do I write a for loop that finds the product of natural numbers from 1 to 50.
i.e. 1x2x3x4...x50
  댓글 수: 3
Stephen23
Stephen23 2019년 4월 23일
Cebolenkosi Mandlanti's "Answer" moved here:
Not too accurate, I just want know how do I put it together.
Stephen23
Stephen23 2019년 4월 23일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Ravi Chaitanya
Ravi Chaitanya 2022년 12월 29일
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!

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by