c++ for loop converted to a while loop

后端 未结 3 1019
一生所求
一生所求 2021-01-29 09:11

Hi I wrote this code to print out factors of an integer with a for looop

how do i write it with a while loop?

for(int i = 1; i <  integer+1; i++)
{
           


        
3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-29 09:27

    Following code will print the same result as your for loop in printing.

     int i = 1;
        while(i < integer + 1)
        {
            if(integer % i == 0)
             {   cout<< i<<" "; }
             i++;
    
        }
    

提交回复
热议问题