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

16 views (last 30 days)
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

Arif Hoq
Arif Hoq on 6 Mar 2022
Edited: Arif Hoq on 6 Mar 2022
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

Find more on Discrete Math in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!