0

Print of Prime numbers

Hi guys! Please help me to write code this problem above: Title: Learning Prime numbers with Loop/Recursion Problem: Raja Beta is bad at maths, his teacher always complaints about him.Help him in his prime numbers homework. Input: Two space separated positive integer m and n Output: Print all prime numbers p such that m <= p <= n, one number per line Constraints: 1 <= m <= n <= 1000000000 Sample Input: 1 10 Sample Output: 2 3 5 7

23rd Feb 2017, 1:25 PM
Mohamed Abdalla
Mohamed Abdalla - avatar
1 Réponse
0
If you wan't to get prime numbers you'll need to create loop to check if any number (lesser or equal than half) can be fully divided so: //here add your variables: m, n for(int i = m; m<=i && i>=n; i++) { for(int divider = 2; divider<=(i/2); divider++) { if (i%divider == 0) { cout<<p<<endl; break; //to stop looping } } } hope this helps
23rd Feb 2017, 5:16 PM
Mat
Mat - avatar