Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
0
This program calculates the sum of primes 1 through n entered by the user. The trickiest part for me was getting the test for prime right. For any number A, we loop though all the numbers B from 2 up to A/2. if A % B != 0 then A is prime. That is to say if any A cannot be divided evenly by any number from 2 up to A/2 then A is prime: https://code.sololearn.com/#cpp
24th Nov 2017, 10:28 PM
Phill