When I run this program it shows erron in line 4.

n = input("ENTER A NUMBER "); flag = 0 ; for i=1:n if (modulo(n,i)==0) then flag = flag+1 ; end end if (flag==2)then disp("this is a prime number "); else disp("this is not prime ."); end

 Accepted Answer

use 'mod' function in the for loop.
n = input("ENTER A NUMBER ");
flag = 0 ;
for i=1:n
if (mod(n,i)==0)
flag = flag+1 ;
end
end
if (flag==2)
disp("this is a prime number ");
else
disp("this is not a prime number ");
end

More Answers (0)

Categories

Asked:

on 6 Mar 2022

Edited:

on 6 Mar 2022

Community Treasure Hunt

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

Start Hunting!