Loop in C++ MCQs Exercise I


Ques 1 Loop


What is the output of following code?


int main() 
{
    int i=1,x=1;
    do
    {
      if(i%5==0)
      {
        cout<<x;
        x++;
      }
      ++i;
    }while(i<10);
    cout<<x;
    return 0;
}

  a) 1
  b) 12
  c) 2
  d) 123


b is the correct option





Ques 2 Loop


What is the output of fallowing code?


int main() 
{
  int i=0,x=1;
  for(i=1;i<10;i*=2)
  {
     x++;
     cout<<x;
  }
  cout<<x;
  return 0;
}

  a) 23455
  b) 23445
  c) 23345
  d) 23454


a is the correct option





Ques 3 Loop


How many types of "SmallCode" in the output screen?


int main()
{
  for(int i=0; i< 5; i++);
	 cout<<"smallcode.com";
  return 0;
}

  a) 0
  b) 1
  c) 4
  d) 5


b is the correct option





Ques 4 Loop


What is the output of following code?


int main()
{
  int x = 10;
  while (x>0)
    x--;
    cout<<x;
  return 0;
}

  a) 987654321
  b) 9876543210
  c) 9
  d) 0


d is the correct option