Filter löschen
Filter löschen

finding next prime number

1 Ansicht (letzte 30 Tage)
Abhishek singh
Abhishek singh am 31 Mär. 2019
Beantwortet: Walter Roberson am 31 Mär. 2019
function k=next_prime(n)
while true;
n = n+1
for i in rng(2:n):
if mod(n,i) == 0
break
else
return k
#getting error
Error in solution Line: 4 Column: 11
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

Antworten (1)

Walter Roberson
Walter Roberson am 31 Mär. 2019
MATLAB does not use colon as a statment separator or statement terminator. You should remove it from the end of your for line.
Note: when the first parameter to the rng() function is numeric, then the parameter must be a scalar, not a vector of integers.
Note: the rng() function always returns a structure that gives information about the internal state of the random number generator. The mod() function will not accept that structure as the second parameter to mod().

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by