While8. Дано целое число N (> 0). Найти наибольшее целое число K, квадрат которого не превосходит N: K2 ≤ N. Функцию извлечения квадратного корня не использовать.
>Решение Pascal
1 2 3 4 5 6 7 8 9 10 | program While8; var N,k :Integer; begin Write('Введите N: '); Readln(N); K:=1; while Sqr(K)<=N do inc(K,1); Writeln(K-1); end. |
>
Решение C
1 2 3 4 5 6 7 8 9 10 11 | #include int main(void) { int n; printf("N:"); scanf ("%i", &n); int k=1; while (k*k<=n) ++k; printf("K: %i\n",k-1); return 0; } |
Решение C++
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <iostream> using namespace std; int main() { setlocale(LC_ALL, "Rus"); int n; cout<<"N:"; cin>>n; int k = 1; while (k*k <= n) ++k; cout<<k - 1; return 0; } |
import java.io.PrintWriter;
import java.util.Scanner;
public class While8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
System.out.println(» N Sonni kiriting: «);
int n = sc.nextInt();
int k = 1;
while (k*k<=n)++k;
System.out.println("Kvadrati " +n+ " dan katta bo'lmagan eng katta butun K soni:"+(k-1));
}
}
c#
Console.Write(«N = «);
int N = Convert.ToInt32(Console.ReadLine());
int K = 1;
int num = 0;
while (K = N) break;
K++;
}
Console.WriteLine(K);