Find a number which when divided by 2 ,3 ,4 ,5 ,6, 7 ,8 , 9 ,10 individually gives remainder 1 and when divided by 11 gives remainder 0 find a number which when divided by 2 ,3 ,4 ,5 ,6, 7 ,8 , 9 ,10 individually gives remainder 1 and when divided by 11 gives remainder 0.

There is one question posted on geeksforgeeks.con under SAP interview questions. Though it is a simpler one but still I like to share the code with the interested people.

Here is the code :


#include <iostream>
#include <conio.h>

using namespace std;

void main()
{
  int result = 11;
  bool found = false;

  for (; !found; result += 11)
  {
    found = true;

    for (int index = 2; index <= 10 && found; ++index)
    {
      found &= (result % index) == 1; 
    }
  }

  result -= 11;

  cout << result;
  _getch();
}

Thanks.

Comments

Popular Posts