C#: Find the first two-digit number equal to the square of the number of its units, with a dozen cc.



  • Use the operator while, no do. I tried and only did it with a do/while:

            var random = new Random();
            int x, y;
            do
            {
                x = random.Next(1, 9);
                y = random.Next(1, 9);
            }
            while (x * 10 + y != x * x * x + y * y);
            Console.WriteLine($"{x}{y}");
    

    Please redesign this code to the cycle while.



  • let x = 1, y = -1;
    while (x * 10 + y != x * x * x + y * y && x < 10) {
      y++;
      if (y == 10) {
        y = 0;
        x++;
      }
    }
    console.log(x == 10? "No number" : `${x}${y}`);


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2