Home c# Task about squares on C #

Task about squares on C #

Author

Date

Category

I can not think about how to check what the root is full, help.
Input
Includes integers a and b. It is guaranteed that a does not exceed b.
(2 8)
Output
Out all the numbers on the segment from A to b, which are full squares. If there are no such numbers, it is not necessary to output anything.
(4)


Answer 1, Authority 100%

I will describe the algorithm verbally, because I do not know C #.

  1. organize a cycle from the nearest one for SQRT (a) to
    Next of the nearest bottom for SQRT (B) in one.
  2. On each iteration, we display the square of the cycle counter.

Actually, all.


Answer 2

calculate the square root from among, using the difference algorithm.
Algorithm: From among the root of which we need, the odd numbers are subtracted in turns until the exit residue is less subtracted or equal to zero.
The number of moves and will end up with a desired number. For example, the calculation of the square root of 25: 25-1 = 24, 24-3 = 21, 21-5 = 17, 17-7 = 10, 10-9 = 1.
There were only 5 iterations, therefore, square root out of 25 = 5.
// A whole root - the root of the number without fractional numbers, rounding to smaller (3.9 = 3; 19.50125010 = 19)
using System;
Namespace Program
{
  Class Program
  {
    Public Static Void Main (String [] Args)
    {
      Console.WriteLine ("Enter the first number");
      int a = convert.TOINT32 (Console.Readline ());
      Console.WriteLine ("Enter the second number");
      int b = convert.TOINT32 (Console.ReadLine ());
      INT SQRTA = 0, SQRTB = 0; // reset the counters, ultimately, these counters will be the whole root (the whole root 65 = 8)
      For (int i = 1; i & lt; int32.maxvalue; i + = 2) {// (i = 1,3,5,7,9,13,15 ...) If (A & GT; = i) then {ai ; The amount of iterations (counter) +1; }
        if (a & gt; = i) {
          a- = i;
          SQRTA ++;
        }
        ELSE BREAK;
      }
      for (int i = 1; i & lt; int32.maxvalue; i + = 2) {// (i = 1,3,5,7,9,13,15 ...) if (b & gt; = i) then {Bi ; The amount of iterations (counter) +1; }
        IF (B & GT; = i) {
          b- = i;
          SQRTB ++;
        }
        ELSE BREAK;
      }
      Console.Writeline ("The whole root of the number A = {0} is a whole root of the number B = {1}", SQRTA, SQRTB); // * For clarity, you can delete the string completely
      For (int i = SQRTA; I & LT; = SQRTB; I ++) {
        Console.Write (i + "); // numbers lying in the range from root A to the root B * For clarity, you can delete the string completely
        Console.Writeline (I * i); // "Full Squares" lying in the range from A to B
      }
      Console.ReadKey (TRUE);
    }
  }
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions