Computer Science, asked by devjob9923, 10 months ago

C++ program to find prime number between 1 and 100

Answers

Answered by gurukulamdivya
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