C#

Написать программу на С#

Дано целое число N (>0). Найти наибольшее целое число K, квадрат которого не превосходит N: K^2≤N. Функцию извлечения квадратного корня не использовать.
EE
Evg Evg
430
using System;

public static class Globals
{
public static 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 using namespace std;

internal static void Main()

{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);

int N;
int K = 1;
Console.Write("Введите целое число N (>0): ");
N = int.Parse(ConsoleInput.ReadToWhiteSpace(true));
while (K * K <= N)
{
++K;
}
Console.Write("Наименьшее целое положительное число K, квадрат которого превосходит N: ");
Console.Write(K);
Console.Write("\n");
system("pause");
}
}

internal static class ConsoleInput
{
private static bool goodLastRead = false;
public static bool LastReadWasGood
{
get
{
return goodLastRead;
}
}

public static string ReadToWhiteSpace(bool skipLeadingWhiteSpace)
{
string input = "";

char nextChar;
while (char.IsWhiteSpace(nextChar = (char)System.Console.Read()))
{
//accumulate leading white space if skipLeadingWhiteSpace is false:
if (!skipLeadingWhiteSpace)
input += nextChar;
}
//the first non white space character:
input += nextChar;

//accumulate characters until white space is reached:
while (!char.IsWhiteSpace(nextChar = (char)System.Console.Read()))
{
input += nextChar;
}

goodLastRead = input.Length > 0;
return input;
}

public static string ScanfRead(string unwantedSequence = null, int maxFieldLength = -1)
{
string input = "";

char nextChar;
if (unwantedSequence != null)
{
nextChar = '\0';
for (int charIndex = 0; charIndex < unwantedSequence.Length; charIndex++)
{
if (char.IsWhiteSpace(unwantedSequence[charIndex]))
{
//ignore all subsequent white space:
while (char.IsWhiteSpace(nextChar = (char)System.Console.Read()))
{
}
}
else
{
//ensure each character matches the expected character in the sequence:
nextChar = (char)System.Console.Read();
if (nextChar != unwantedSequence[charIndex])
return null;
}
}

input = nextChar.ToString();
if (maxFieldLength == 1)
return input;
}

while (!char.IsWhiteSpace(nextChar = (char)System.Console.Read()))
{
input += nextChar;
if (maxFieldLength == input.Length)
return input;
}

return input;
}
}
ИЗ
Игорь Захарченко
72 487
Лучший ответ
ну это значит что N лежит от к квадрат до к+1 квадрат
k²<=N<=(k+1)²
ну сам там вставь в мейн, на шарфе давно не писал
public static void main(String[] args)
{
int N=как ввести не сказал;
for(int k=1 ; (k*k<=N)&&(N<=(k+1)*(k+1)) ; k++)
{}
console.println(k);
}
Витя Петров
Витя Петров
17 648