My issue
The last challenge of the while loop.
Chef wants to write a code which checks if a given number is prime.
You are given an integer
N
N
You need to output ‘Yes’ or ‘No’ depending on whether the number is prime or not.
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n < 2) { // special cases
cout << "No";
return 0;
}
int i = 2;
bool isPrime = true;
while (i < n) {
// check if n is divisible by current number
if (n/i) {
// if n is divisble by current number, set isPrime to false
}
//update i
i++;
}
if (isPrime) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
Learning course: Learn C Programming
Problem Link: https://www.codechef.com/learn/course/rcpit-programming-c/RCPITLPC21/problems/RCPITCP144