Вопрос задан 28.02.2019 в 19:19. Предмет Информатика. Спрашивает Кузьменко Настя.

Найти и исправить ошибки в программе.Задача 4-1proram Z;VAR n,m: char;BEGINwrite(n -> );

readln(m)m:=1;while sqr(m)>=n do m:=m+1;writeln(m);ENDЗадача 4-2program Д;BEGINVAR i,n,k,a: integer;readln(n); k:=0;for i:=1 to n doreadln(a);if a > 0 then k:=k+1;end;wreteln(k = ',k:0:2);END.Задача 4-3program W;VAR max;a: integer; n: longint;BEGINwrite('n -> '); readln(n);max:=10;while n <> 0 begina:=n mod 10;if a > max;then max:=a;n:=n mod 10;endreadln(max);END
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Жуклин Андрей.
Как-то так:
program Z;
var
n, m: Byte;
begin
write('n = ');
readln(n);
m:=1;
while sqr(m)>=n do m:=m+1;
writeln('M = ', m);
end.

Задача 4-2:
program D;
var
i,n,k,a: integer;
begin
write('n = ');
readln(n);

k:=0;

for i:=1 to n do
begin
readln(a);
if a > 0 then k:=k+1;
end;

wreteln('k = ', k:0:2);
end.

Задача 4-3:
program W;
var
max, a: integer;
n: longint;
begin
write('n = ');
readln(n);
max:=10;
while n <> 0 do
begin
a:=n mod 10;
if a > max then max:=a;
n:=n mod 10;
end;

readln(max);
end.

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

I'm sorry, but I'm unable to execute or debug code directly. However, I can help you understand the logic of the code and suggest possible improvements. Let's go through each task and discuss them one by one.

Task 4-1:

The code you provided seems to have some syntax errors. Here's the corrected version:

```pascal program Z; VAR n, m: char; BEGIN write('n->'); readln(n); m := '1'; while sqr(ord(m)) >= ord(n) do m := chr(ord(m) + 1); writeln(m); END. ```

In this code, it appears that the program is trying to find the smallest character `m` such that `m^2 >= n`. The program takes input for `n` and iteratively increments `m` until the condition is met. Finally, it prints the value of `m`.

Task 4-2:

Here's the corrected version of the code:

```pascal program D; VAR i, n, k, a: integer; BEGIN readln(n); k := 0; for i := 1 to n do begin readln(a); if a > 0 then k := k + 1; end; writeln(k:0:2); END. ```

This code seems to count the number of positive integers entered by the user. It takes input for `n`, which represents the number of integers to be entered. Then, it reads `n` integers one by one and increments `k` if the integer is greater than 0. Finally, it prints the value of `k` with 2 decimal places.

Task 4-3:

Here's the corrected version of the code:

```pascal program W; VAR max, a: integer; n: longint; BEGIN write('n->'); readln(n); max := 10; while n <> 0 do begin a := n mod 10; if a > max then max := a; n := n div 10; end; writeln(max); END. ```

This code seems to find the maximum digit in a given number `n`. It takes input for `n` and initializes `max` to 10. Then, it iteratively extracts the last digit of `n` and updates `max` if the extracted digit is greater than the current `max`. Finally, it prints the value of `max`.

I hope this helps! Let me know if you have any further questions.

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос