Prime Number

/*Hi everybody
This shows any prime number between a and b and also counts them*/


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>

using namespace std;

int main(){
int a;
int b;
cout << "\nenter the first Number : " ;
cin >> a;
cout << "enter the second Number : " ;
cin >> b;
cout << "\n\n\n";
int min = (a<b ? a : b) ;
int max = (a>b ? a : b) ;
int m=0;
if ((max==1 && min==1) || (max==0 && min ==0)){
 cout << "I think you are not OK . Maybe you should try later . " ;
}
else if   (min <= 2){
  cout << 2 << "\t" ;
  ++m;
}

for (int k=min ; k<max ; ++k ){
    int c = 0;
    int v = k%2;
    k = (v!=0 ? k : ++k);
            for (int i=1 ; i<=(k/2) ; ++i){
            int r=k%i;
                if(r==0){
                c++;
                }
            }

        if (c==1){
        cout <<k<<"\t";
        m++;
        }
    }
cout << "\n\n\n";
cout << "The Number of PRIMES between " <<min<<" and " <<max<<" is : "<<m<<"\n\n\n";

return 0;
}
"cout << "\nenter the first Number : " ;"
There is a typo, pal.
Assuming you just started programming, it's pretty cool! Keep this up!
Topic archived. No new replies allowed.