Write a C++ program to print all the prime numbers from 1-1000 (1 and 1000 inclu
ID: 3634483 • Letter: W
Question
Write a C++ program to print all the prime numbers from 1-1000 (1 and 1000 included).Hint:
1. Declare a global array (int primeList [180]) to store all detected prime numbers.
set primeList[0] = 2; and
primeList[1] = 3;
2. implement a for loop from i = 4 to 1000 and test each time i for its primality through a function isPrime (int n).
3. In isPrime(int n) function, check for whether number is divisible by numbers already stored in primeList array. If divisible then number is not prime otherwise its prime. Store the newly detected prime in the primeList array.
4. At the end display each element of primeList array.
**please only use <iostream>, <cstring>, <cmath> libraries because thats all we have learned so far, thanks!**
Explanation / Answer
#include using namespace std; bool isprime(int j) { int k; for (k=2; kRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.