For to while conversion – CSKC
Sign In

Search

Solved Problem! #CPP#3001    siteicon   siteicon  

Problem Statement - For to while conversion

Write the following program again using the while loop instead of for loop

TC++ #3001

 

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

  Related ( ? ) :

Solution


The program can be rewritten as follows.

#include <iostream>
using namespace std;
int main() 
{
  int i=50;         //The first instruction of for loop comes before while loop
  while(i>=10)      //The condition check remains here after while
  {
    cout<<i/2<<" "; //These are body instructions
    i-=10;          //The update instruction comes here as last instruction of loop body.
  } 
  return 0;
}

 


Share

Created: 25-Jan-2018 01:06 | Updated: 29-Nov-2018 17:15|