Hi! I am new to C++ and I am trying to learn on my own, so I tried to make a program that verifies if a number is prime or not. It shows no errors and when I run it, it will ask for number input, but then nothing happens. Any suggestions on how to fix this will be much appreciated!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include<iostream>
usingnamespace std;
int main()
{
unsignedint a, n, i=0;
cout << "Input a natural number: ";
cin >> a;
for (n = 2; n < a; ++n)
{
if (a % n == 0)
{ i++; }
}
if (i == 0)
{ cout << "This number is prime"<<endl; }
else
{ cout << "This number is not prime"<<endl; }
}
It works for you? I entered several numbers, one of them was 13. I am using visual studio 2019 for the first time, maybe I'm doing something wrong. Thanks for letting me know that the program works though. Cheers:)