Message from C, C++ talks

June 2019

— What have you tried? Some code?

— Print prime number out on the screen

— Okay let me send you the code then

— Send it here, not to me


#include <iostream>

using namespace std;

int main()

int a;
int d=2;
cout << "Please enter your number \n";
for( d>=a; d++){
cout << "prime\n";
else {
cout << "Not prime \n";

return 0;

— But is not working

— I have tried but still not working please

— It's wrong algorithm

— It should be d <= a

— And sqrt mb ?

— Also you should move than int d=2; into the for, like so:
for(int d = 2; d <= a; d++)

— Yep

— If he's testing small numbers it might be slower, but for anything slighly larger, yes

— Steve if a number isn't divisable (with a remainder of 0) by any of the numbers smaller than it's square root, it's prime

Message permanent page

— So you're doing some unnecessary checks