closed account (18RGNwbp)

 ``123456789101112131415161718192021222324`` `````` #include #include #include #include using namespace std; int main() { // Function A: Numbers divisible by 5, 6, 9, and 10 int k, Hold; k = 0; while ( k < 20 ) { Hold = rand(); if ( Hold > 101 && Hold < 3000 && Hold % 5 == 0 && Hold % 6 == 0 && Hold % 9 == 0 && Hold % 10 == 0 ) { cout << setw(4) << Hold << endl; k = k+1; } } }``````

However, can someone please help me with code on how to calculate prime numbers. There must be two different functions: One must be a list of 20 random, prime numbers greater than 100 and less than 2000. The other function must be a list od 20, random, prime numbers greater than 200 and less than 5000.
Please try to use code, similar to the one shown above.
with this code you can calculate prime numbers between the range that you want. However i can't do it randomly!
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051`` ``````#include using std::cout; using std::cin; using std::endl; #include using std::sqrt; bool prime(int number); //function prototype int main(){ int numberOfPrimes=0; int firstNumber; int secondNumber; cout<<"Find primes numbers from: "; cin>>firstNumber; cout<<"To(greater than the first number please!): "; cin>>secondNumber; cout<<'\n'; for(int number=firstNumber;number<=secondNumber;number++){ if(prime(number)==true){ ++numberOfPrimes; cout<<"["<

 ``` Find primes numbers from: 2 To(greater than the first number please!): 10 [2] is prime [3] is prime [5] is prime [7] is prime Found: 4 ```
Last edited on
Topic archived. No new replies allowed.