This Code is Not Working [Help!] [C++]

[code]
#include

using namespace std;
int main(){int q=0;
int n;
cout<<"Enter:
";
cin>>n;

for(int i =1;i<=n;++i){int k=0;
for(int j =0;j<=i;j++){
if(i%j==2){
++k;
}
}
if(k == 2){
cout<<i;
}
cout<<"
";
}


return 0;}

[/code]


The Above code is not working.. when compiled and ran (using [b]CodeBlocks[/b]) the top [b]cout[/b] statement works, after entering the value of 'n', the ".exe" stops working. Why is that? Please Help

[hr]

The code was for printing primes till 'n'
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories