Question #331094

The following code is supposed to display the positive even numbers less than 12. That is, it will output the numbers 2, 4, 6, 8 and 10. However, there is a logical error in the code. Explain what the output of the code below will be. Then write a small program including the code below and make the necessary changes to fix the code so that it displays what it is intended to display. Ensure that your program works correctly. Only submit the program, not the output.


Expert's answer

//NOTICE I don't see your code but I write is working code




#include <iostream>
using namespace std;
int main()
{
  
  int n;
  cout<<"Enter n: ";
  cin>>n;
  for(int i=2;i<n;i+=2)
    cout<<i<<"  ";
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS