In: Computer Science
(C++)Change the following loop to a while loop:
int i;
for (i=0; i<10; i++)
{
cout<<i<<endl;
}
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new c++ program with name "main.cpp" is created, which contains following code.
main.cpp :
//header files
#include <iostream>
using namespace std;
//main method
int main()
{
int i;//declaring variable
i=0;//initilizing variable
//using while loop
while(i<10)
{
cout<<i<<endl;//print value of i
i++;//increment i
}
return 0;
}
======================================================
Output : Compile and Run main.cpp to get the screen as shown below
Screen 1 :main.cpp
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.