#include <iostream> using namespace std; int main() { int n, i, flag=0; cout << "Enter a positive integer: "; cin >> n; for(i=2;i<=n/2;++i) { if(n%i==0) { flag=1; break; } } if (flag==0) cout << "This is a prime number"; else cout << "This is not a prime number"; return 0; } Code (markup):
More homework? How about you tell us what you understand and what you don't and we can fill in the gaps
Everything I post here is not a home work. I'm just learning programming and I don't want to cram. What I know about prime is the number which can be divided by one or itself. The first condition I have already understood even number can't be prime number when reminder is zero. More I want to know when flag is set equal to one. How does the program detect that number can be divided with one or itself