IBM Interview Question
644 Interview Reviews |
Back to all IBM Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Engineer at IBM:
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (3)
Also if n is our number, you don't need to go from 2 to n, from 2 to sqrt(n) will do the job
Helpful Answer?
Yes |
No
Inappropriate?
so:
int j=0;
for (int i=1;i<=n/2;i++)
{
if(n%i==0)
j++;
}
if (j==1)
return prime;
else
return not prime;
j=0;
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up
0 of 0 people found this helpful
by Bhavin Mehta:
for example, say number 17. Run a loop from 1 to 16. On each loop instance, divide 17 with the loop counter number (1..2......16 etc) and check for remainder. None of these number will give you any other remainder than 17 because 17 is a Prime number. Check the logic yourself with 1, 3, 7, 13, 17,19, ....
Hope it helps! Please, reply if someone finds any logical errors in it.