Prime Numbers between 0 and 100

A question that was asked to me few days ago..

After a long time, I wrote a code in C programming language..

This is the code for that process.

Screenshot from 2012-12-26 15:35:19

//We start with 2 because 2 is the smallest prime number.Because the comments are Turkish, I’d like to explain it a bit. It will be in the same order with comments that are written.

//Because it says that smaller than 100 in question

//if it is prime, isPrime will be 1 (to mean it is true)

//the variable ‘div’ is used to check numbers smaller than our current number if they are divisible or not

//if it can be divided, then the remainder will be zero

//if it is divided, current number is not a prime number

//(the -break- line) if it is divisible by any number, we don’t need to check the others

//if our number didn’t divide by any number above, then it is prime

//we add it to the end of the array (of found primes) and increment to number of total numbers found

//we increment -current- to check next number

//I used div as a temporary loop variable here

// I printed out the _div+1_ because the array starts from zero

//If you ask -why is the array for 50 integers?- I thought that there is 50 odd numbers and most of them are not prime. I continued, let’s take as if all of them are prime, there will be 51 ( because the only even prime number is 2. (50+1)). Then array of 50 will be enough… You can also see if you compile it, there is 25 prime numbers…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s