ramylan00
ramylan00 ramylan00
  • 19-12-2020
  • Computers and Technology
contestada

write c++ program from 1to 100 to find prime numbers using statement.​​

Respuesta :

lialeix
lialeix lialeix
  • 19-12-2020

#include <iostream> using namespace std; int isPrimeNumber(int); int main() { bool isPrime; for(int n = 2; n < 100; n++) { // isPrime will be true for prime numbers isPrime = isPrimeNumber(n); if(isPrime == true) cout<<n<<" "; } return 0; } // Function that checks whether n is prime or not int isPrimeNumber(int n) { bool isPrime = true; for(int i = 2; i <= n/2; i++) { if (n%i == 0) { isPrime = false; break; } } return isPrime; }

Answer Link

Otras preguntas

how to integrate a/1-ay?
How are decomposers useful
What happens in any chemical change?
You have decided to select a new car by using the scientific method. how would you proceed? Please answer!!!
The atmosphere contains about 80% nitrogen gas, but nitrogen in this form cannot be used by plants. Which process converts atmospheric nitrogen to a useful
An AHA peeling solution has PH of 3.83 What would be the percentage of available acid ……and the percentage of salt….
Plz help it is a probability question it is soo hard - I have tried and tried
An earthquake takes place in which sphere?
What is one way in which objects transfer momentum? Explain.
Why do particles in gases and liquids diffuse, but not solids?