Question

Use a Mathlab program using the while/for command and run it for the following exercise. 20. A twin primes is a pair of prime
0 0
Add a comment Improve this question Transcribed image text
Answer #1

twins=[];
j=1;
for i=10:498
    if checkPrime(i) && checkPrime(i+2)
        twins(j,:)=[i,i+2];
        j=j+1;
    end
end
disp(twins)
function [check]=checkPrime(num)
check=0;
for i = 2:sqrt(num)
    if rem(num,i)==0
        check=1;
        break
    end
end
if check==1
    check=false;
else
    check=true;
end
end

twinPrime.m+ Users Vaibhav Documents MATLAB2 twins= [ ] ; Command Window >> twinPrime 13 19 31 43 61 73 101 103 107 109 137 1

Add a comment
Know the answer?
Add Answer to:
Use a Mathlab program using the while/for command and run it for the following exercise. 20. A twin primes is a pair of prime numbers such that the difference between them is2 (for example, 17 an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT