Originally Posted by
bos1234
as fader_berg mentioned...
any prime number above greater thn 1 is only divisibly by 1 or itself.
example, say you enter 5 terms.
5%1=0 --->c=1
5%2=1
5%3=2
5%4=1
5%5=0---->c=2
so say you want first 5 prime numbers =n
you initialise i=1. Is 1<5? yes, so enter the while loop
enter the for loop since j=1 and j<=i i.e.1<=1
1%1=0 so increment c from 0 to 1.
you CAN'T enter the for loop again since j=2 and 2<=1. So fall through the loops and go to i++
i=2 now
enter the for while loop since 2<=5
enter the if loop and check if 1%1=0. It does so increment c.
c=1
Run through the for loop again this since j=2 and 2<=2
enter the if loop and see if 2%2=0. It does so increment c to 2. c=2
Leave the for loop amd go to the second if statement. It says if c==2 print i.
So it will print 2
now follow the same procedure for 3, 4 etc...