A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Prime Number in Matlab page! Here, you'll find the source code for this program as well as a description of how the program works.
function result = prime_number(n)
if n < 0
result = 'Please input a non-negative integer'
end
if not(ischar(n))
result = 'Please input a non-negative integer'
end
if not(isempty(n)) = 1
result = 'Please input a non-negative integer'
end
if not(~isinf(x) & floor(x) == x)
result = 'Please input a non-negative integer'
end
if n == 0 | n == 1
result = 'Neither Prime nor Composite'
end
m = 2;
isprime = 1;
while (m <= sqrt(n))
if(rem(n, m) == 0)
isprime = 0;
break;
end
m = m + 1;
end
if(isprime == 1)
result = 'Prime'
else
result = 'Composite'
end
Prime Number in Matlab was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.