Write a MATLAB program for display prime numbers 1 to 100 using for loop and break

Code:

 

clc;
clear;
disp('Prime Number List 1 to 100');
for i=2:100
for j=2:100
if(~mod(i,j))
break; % if factor found, not prime
end
end
if(j > (i/j))
fprintf('%d is prime\n', i);
end
end

 


Output:



3 comments:

Powered by Blogger.