Если лень перебирать вручную, можно воспользоваться программой
var k,l,r,x,f:integer; begin f := 3001; l := 0; r := 65534; x := (l + r) div 2; k := 1; while (x <> f) and (l < r) do begin writeln(k,' ',l,' ',r,' ',x); k := k + 1; if f < x then r := x - 1 else l := x + 1; x := (l + r) div 2 end; writeln(k,' ',l,' ',r,' ',x); end.
Решение Pascal
Delphi/Pascal
program Case5;
var
N,A,B:Integer;
begin
Write('Введите номер действия: ');
Readln(N);
Write('Введите число A: ');
Readln(A);
Write('Введите число B: ');
Readln(B);
Case N of
1: Writeln(A+B);
2: Writeln(A-B);
3: Writeln(A*B);
4: Writeln(A/B);
end;
end.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
program Case5;
var
N,A,B:Integer;
begin
Write('Введите номер действия: ');
Readln(N);
Write('Введите число A: ');
Readln(A);
Write('Введите число B: ');
Readln(B);
Case N of
1: Writeln(A+B);
2: Writeln(A-B);
3: Writeln(A*B);
4: Writeln(A/B);
end;
end.
Решение C
C
#include <stdio.h>
int main(void)
{
system("chcp 1251");
int n;
float a,b;
printf("N:") ;
scanf ("%i", &n);
printf("A:") ;
scanf ("%f", &a);
printf("B:") ;
scanf ("%f", &b);
switch (n) {
case 1:
printf("%f\n",a+b) ;
break;
case 2:
printf("%f\n",a-b) ;
break;
case 3:
printf("%f\n",a*b) ;
break;
case 4:
printf("%f\n",a/b) ;
break;
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
int main(void)
{
system("chcp 1251");
int n;
float a,b;
printf("N:") ;
scanf ("%i", &n);
printf("A:") ;
scanf ("%f", &a);
printf("B:") ;
scanf ("%f", &b);
switch (n) {
case 1:
printf("%f\n",a+b) ;
break;
case 2:
printf("%f\n",a-b) ;
break;
case 3:
printf("%f\n",a*b) ;
break;
case 4:
printf("%f\n",a/b) ;
break;
}
return 0;
}
Объяснение:
1. 0..65534 -> 32767
2. 0..32766 -> 16383
3. 0..16382 -> 8191
4. 0..8190 -> 4095
5. 0..4094 -> 2047
6. 2048..4094 -> 3071
7. 2048..3070 -> 2559
8. 2560..3070 -> 2815
9. 2816..3070 -> 2943
10. 2944..3070 -> 3007
11. 2944..3006 -> 2975
12. 2976..3006 -> 2991
13. 2992..3006 -> 2999
14. 3000..3006 -> 3003
15. 3000..3002 -> 3001
Если лень перебирать вручную, можно воспользоваться программой
var k,l,r,x,f:integer;
begin
f := 3001;
l := 0;
r := 65534;
x := (l + r) div 2;
k := 1;
while (x <> f) and (l < r) do
begin
writeln(k,' ',l,' ',r,' ',x);
k := k + 1;
if f < x then r := x - 1
else l := x + 1;
x := (l + r) div 2
end;
writeln(k,' ',l,' ',r,' ',x);
end.