C++ program to find prime number between 1 and 100
Answers
Answered by
0
Answer:
#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;
}
Similar questions
English,
6 months ago
Hindi,
6 months ago
Social Sciences,
6 months ago
Physics,
1 year ago
Physics,
1 year ago
Social Sciences,
1 year ago