So, I am trying to find prime numbers between 1 and 100. I know what prime numbers are. I am using this technique to come up with the prime numbers:
a) I will make a vector of primes, push_back the prime number "2" as the first prime number.
b)Choose an iterator "i", iterate from numbers starting at 3 and ending at 100.
c) To check if a no. is prime or not, I check whether it is divisible by previous stored prime numbers.(So when i start with number-"3", i see if it is divisible by "2",which is my previously stored no.)
d)I am trying to do something like this: i%prime[j]!=0, then store the number.
"j" is used for indexing vector prime.
I do think, this is how the problem should be tackled, but still, I am stuck bad.
mine? it is not complete. you must add the main function, header file(s) and use the std namespace.
if u enter the num=6
how will that work
it would init i=1, check if when 1 enters into 6, there is a remainder of 0. if positive, then iFactor++. then i++(i=2) also checks if i(2) enters 6 with a remainder of 0.
It does this until i>num(6), then checks if iFactor=2(ie: for a prime number) since prime numbers have two factors.