+ 1

I need help

I need to find all divisors of 2258 how to code it? #include <iostream> #include <math.h> using namespace std; int main() { int b; for(int i=0;i<2258;i++){ b=2258/i; if(b%b==0) cout<<i<<" "; }} but writing that is no output

15th May 2017, 7:22 AM
Jimmy Pub
Jimmy Pub - avatar
9 Answers
+ 1
changed Code and it's working, thanks everyone
15th May 2017, 7:56 AM
Jimmy Pub
Jimmy Pub - avatar
0
You put a ";" after your if statement when you test the modulus. Also you only need to do "if (2258 % i == 0)"
15th May 2017, 7:33 AM
aklex
aklex - avatar
0
deleted ; but it didn't help
15th May 2017, 7:35 AM
Jimmy Pub
Jimmy Pub - avatar
0
try b=2258 and b%i
15th May 2017, 7:40 AM
Daemo
Daemo - avatar
0
You are also dividing by zero on the first iteration. That will cause problems or even a crash. You cant divde by zero in c++
15th May 2017, 7:43 AM
aklex
aklex - avatar
0
I tried this code, but no output again...((
15th May 2017, 7:44 AM
Jimmy Pub
Jimmy Pub - avatar
0
or can u wright which numbers are outputed
15th May 2017, 7:50 AM
Jimmy Pub
Jimmy Pub - avatar
0
changed Code and it's working, thanks everyone
15th May 2017, 7:56 AM
Jimmy Pub
Jimmy Pub - avatar