Вариант с циклом while ... do... program z1; uses crt; var n:longint; i,max,x:integer; begin clrscr; read(n); max:=-1; i:=1; {это будет переменная-счетчик} while i<=5 do begin x:= n mod 10; if x>max then max:=x; n:= n div 10; {в этой строке исправлена опечатка в оригинале} i:=i+1; {наращиваем счетчик вручную} end; writeln(max); end.
Вариант с циклом repeat ... until program z1; uses crt; var n:longint;i,max,x:integer; begin clrscr; read(n); max:=-1; i:=1; repeat x:= n mod 10; if x>max then max:=x; n:= n div 10; i:=i+1; until i>5; writeln(max); end.
Вариант с циклом repeat ... until без счетчика! program z1; uses crt; var n:longint; max,x:integer; begin clrscr; read(n); max:=-1; repeat x:= n mod 10; if x>max then max:=x; n:= n div 10; until n=0; writeln(max); end. В последнем примере условием окончания цикла будет случай, когда число станет равным 0. Действительно, после каждого повторения цикла число становится на один разряд меньше (выделенная цветом строка программы), значит, когда-нибудь такое число станет равным 0 (цикл подходит для числа с любым количеством цифр). Пример: 34567 -> 3456 -> 345 -> 34 -> 3 -> 0
program z1;
uses crt;
var n:longint;
i,max,x:integer;
begin
clrscr;
read(n);
max:=-1;
i:=1; {это будет переменная-счетчик}
while i<=5 do
begin
x:= n mod 10;
if x>max then max:=x;
n:= n div 10; {в этой строке исправлена опечатка в оригинале}
i:=i+1; {наращиваем счетчик вручную}
end;
writeln(max);
end.
Вариант с циклом repeat ... until
program z1;
uses crt;
var n:longint;i,max,x:integer;
begin
clrscr;
read(n);
max:=-1;
i:=1;
repeat
x:= n mod 10;
if x>max then max:=x;
n:= n div 10;
i:=i+1;
until i>5;
writeln(max);
end.
Вариант с циклом repeat ... until без счетчика!
program z1;
uses crt;
var n:longint;
max,x:integer;
begin
clrscr;
read(n);
max:=-1;
repeat
x:= n mod 10;
if x>max then max:=x;
n:= n div 10;
until n=0;
writeln(max);
end.
В последнем примере условием окончания цикла будет случай, когда число станет равным 0. Действительно, после каждого повторения цикла число становится на один разряд меньше (выделенная цветом строка программы), значит, когда-нибудь такое число станет равным 0 (цикл подходит для числа с любым количеством цифр). Пример: 34567 -> 3456 -> 345 -> 34 -> 3 -> 0
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cstring>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <climits>typedef unsigned long long ulol;
typedef long double ld;
typedef long long lol;
typedef long int li;#define mp make_pair
#define F first
#define S second
#define sqr(a) ( (a) * (a) )
#define pb push_back
#define INF 999999999
#define ret(a) cout << endl; system("pause"); return(a)
//#define ret(a) return(a)using namespace std;int main()
{
ld x;
cin >> x;
x = ( 8 / sqrt( x ) ) + sqrt(x);
cout << x;
ret(0);
}