Finding factors of a given integer

前端 未结 14 1361
终归单人心
终归单人心 2020-12-16 19:52

I have something like this down:

int f = 120;
for(int ff = 1; ff <= f; ff++){
    while (f % ff != 0){            
}

Is there anything w

14条回答
  •  旧巷少年郎
    2020-12-16 20:00

    It looks like you are not going to do something with either f or ff in your while loop? If so, the expression f%ff != 0 is either false (and then it will go to the next in the for loop), or it is true, and it will end up in an infinite loop.

    Are you sure you need the while like this?

提交回复
热议问题