logo

Crowdly

Create a  function that checks if a number is prime. Return true if it is pri...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Create a  function that checks if a number is prime. Return true if it is prime, false otherwise.

  bool isPrime(int num) {

  if (num <= 1) return false;

  for (int i = 2; i <= num ~/ 2; i++) {

    if (num % i == 0) return false;

  }

  return true;

}

Example Usage:

 

 

void main() {

  print(isPrime(7)); // Output: true

  print(isPrime(10)); // Output: false

}

More questions like this

Want instant access to all verified answers on e-learning.msa.edu.eg?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!