(upbeat music)
- [Instructor] Let's take a look at my solution
for calculating the first 25 prime numbers.
This is 04_solution.cpp from chapter four
of the exercise files.
This solution uses a couple of nested for loops
to iterate through the list of candidates
and the potential factors for each candidate.
The outer loop is pretty simple.
It simply counts from two to 99
and the inner loop tests each number
for its potential factors.
We use a modulus operator
to test if each candidate is a factor
and if it is,
we set the prime flag to false and we break the loop.
If we get out of the loop with the prime flags still true,
then we have a prime number and we print it.
So we'll go ahead and run this
and you see there's our 25 prime numbers.
This is my solution.
Yours may be similar or different as long as it works.
And hopefully you've learned something in the process.