answersLogoWhite

0


Best Answer

My Code:

======================================…

>>

disp('input a pair of natural numbers, N and M with M>N');

N=input('N=');

M=input('M=');

for j=0:(M-N)

Prime=1;

for i=2:((N+j)/2)

if mod((N+j),i)==0

Prime=0;

break

end

end

if Prime==1

disp('This is a Prime number');

else disp('Not Prime');

end

end

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a matlab code to check if a random number is prime or not?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is a prime number always even?

no, 19 is a prime number and it is not even. just a random example.


Is the number 1663561 a prime number?

No, it is not. You can check on prime-numbers.org


Is 4343 a prime number?

No its not a prime number Check out related links


How are prime numbers used in every day life?

Prime numbers have many applications. Some examples are: public key cryptography, hash tables, pseudo-random number generators, and ISBN check digits.


How do you check if a number is a prime or not?

A prime number can only be divided by itself and 1


Write a java programme to check whether the number is twin prime or not?

Find a prime number, add 2 to the number. Check if the new number is prime. IE : 3 is prime. 3+2 =5. 5 is prime. (3,5) are twin primes.


What is the largest prime number you have to check to decide if 221 is prime?

13


What is the largest prime number to check for prime numbers under 100?

the largest prime number under 100 is 97


How do you check if a large number is prime or a composite number?

You divide the number by 2. If the number is able to divide WITHOUT a remainder, then it is a prime number. If you divide a number by 1, you will get the same number. That is not a prime number.


A number that is not prime?

A prime number is any number that only has one and itself as factors. Threfore, any number taht has more than two factors is not prime. Check the the factors of a number to tell if it is prime or not.


Which of these numbers is not a prime number?

A prime number is any number that only has one and itself as factors. Therefore, any number that has more than two factors is not prime. Check the the factors of a number to tell if it is prime or not.


Not a prime number?

A prime number is any number that only has one and itself as factors. Threfore, any number taht has more than two factors is not prime. Check the the factors of a number to tell if it is prime or not.