SwiZzoR

The king "Shlomo"

Jan 29th, 2016
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1.             const int NUMBER_OF_WOMENS = 1000;
  2.             int countNumbers = NUMBER_OF_WOMENS;
  3.             int[] array = new int[NUMBER_OF_WOMENS];
  4.             for (int i = 0; i < NUMBER_OF_WOMENS; i++)
  5.                 array[i] = i+1;
  6.  
  7.  
  8.             while (countNumbers > 1)
  9.                 for (int i = 0; i < NUMBER_OF_WOMENS; i++)
  10.                 {
  11.                     int step = 1, index = (i + step >= NUMBER_OF_WOMENS) ? i + step - NUMBER_OF_WOMENS : index = i + step;
  12.  
  13.                     if (array[i] == 0)
  14.                         continue;
  15.                     while (array[index] == 0) // check how match zeros after the number.
  16.                         index =  (i + step >= NUMBER_OF_WOMENS) ? i + step++ - NUMBER_OF_WOMENS : index = i + step++;
  17.                     array[index] = 0;
  18.                     countNumbers--;
  19.                 }
  20.  
  21.             // print the number
  22.             for (int i = 0; i < NUMBER_OF_WOMENS; i++)
  23.                 if (array[i] != 0)
  24.                     Console.WriteLine("The number of women is : " + array[i]);
Advertisement
Add Comment
Please, Sign In to add comment