My issue
Coding problem - 4
The last challenge of the while loop.
Chef wants to write a code which checks if a given number is prime.
You are given a whole number N.
Your task is to determine if N is a prime number or not and print “Yes” if it is prime, or “No” if it is not.
Sample 1:
Input
Output
14635
No
Sample 2:
Input
Output
13
Yes
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 = 1;
while (i < n) {
// check if n is divisible by current number
if ( i < n) {
// if n is divisble by current number, set isPrime to false
printf("No\n");
}
//update i
return 0;
}
if (isPrime) {
cout << endl;
}
else {
cout << endl;
}
}
Learning course: Programming and Problem solving using C
Problem Link: https://www.codechef.com/learn/course/ciet-programming-c/CIETPC21/problems/PPSC88