Вопрос задан 29.04.2019 в 09:04. Предмет Информатика. Спрашивает Жинь Дима.

Написать программу в паскале:1.Дано целое число. Вычислить, если возможно, натуральный логарифм

этого числа и вывести его на экран. В противном случае вывести сообщение об ошибке.
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Суслинець Христя.
Логарифм существует только для положительных чисел.
Поэтому напишем такую программу:

var  x:integer;
BEGIN
writeln('Введите число');
readln(x);
if  x<=0 then 
     writeln('Логарифм этого числа не существует')
     else write('ln=',ln(x))
END.
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Program in Pascal to Calculate Natural Logarithm

Here is a program in Pascal that calculates the natural logarithm of an integer and displays it on the screen. If the calculation is not possible, it will display an error message.

```pascal program CalculateNaturalLogarithm;

var num: integer; result: real;

begin writeln('Enter an integer: '); readln(num);

if num > 0 then begin result := ln(num); writeln('The natural logarithm of ', num, ' is ', result:0:2); end else writeln('Error: The number must be greater than 0.'); end. ```

Explanation: - The program starts by declaring two variables: `num` to store the input number and `result` to store the calculated natural logarithm. - The user is prompted to enter an integer using the `writeln` and `readln` statements. - The program then checks if the entered number is greater than 0 using an `if` statement. - If the number is greater than 0, the program calculates the natural logarithm using the `ln` function and assigns the result to the `result` variable. - Finally, the program displays the calculated natural logarithm on the screen using the `writeln` statement. - If the number is not greater than 0, the program displays an error message.

Please note that the program assumes you have a Pascal compiler installed and configured properly to run the program.

0 0

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

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

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