# Thread: Matlab prime number with no built in functions

1. ## Matlab prime number with no built in functions

1) Write a program (an m-file) to compute the number of prime numbers for every “century” (i.e., # primes in the range [1-100], in [101-200], in [201-300], etc.) up to 100000. Plot your results. Approximately what percentage of numbers seems to be prime? Is this a good figure for all centuries?

Normally I could use primes, isprime or factor functions but my professor wants us to do it with loops, and conditional statements...

What I'm thinking that this could be a nested for loop? Could someone help me form this script please.What formula would i need to find the number of prime numbers for every century

2. Well, you could brute force it and check to see if a particular number is divisible by all the numbers up until that number. However, there are some tricks that allow one to skip a lot of numbers. First, if a number is even it is not prime, so you only need to check odd numbers. Also, you only need to check if a number is divisible by primes, so if you keep a list that will help. There are probably more shortcuts than that.

,

,

,

,

### undefined

Click on a term to search for related topics.