Help for beginner

Why is this making the program crash?

#include <iostream>
using namespace std;
int main()
{int n,i;
cin>>n;
for(i=0;i<n;i++){
if(n%i==0)cout<<i<<" ";}
return 0;
}
Hi,
What value do you input before your program crashes?

Edit : (n % i) when i is 0 causes undefined behavior.
Last edited on
you cant divide by 0, if you do n%i and you start with i = 0.
ah yeah, I am dumb. Thanks :)
Topic archived. No new replies allowed.