Вопрос задан 09.09.2020 в 16:29. Предмет Информатика. Спрашивает Лубченков Иван.

Найти среднее арифметическое целых чисел в типизированном файле (file of integer), разница

наибольшей и наименьшей цифр которых меньше 5. Если таких чисел нет, то результат- ноль. функция принимает в качестве параметра имя файла Name FUNCTION P(NAME:STRING):DOUBLE;
0 0
Перейти к ответам

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

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

Finding the Arithmetic Mean of Integers in a Typed File

To find the arithmetic mean of integers in a typed file, we need to perform the following steps:

1. Open the file and read the integers. 2. Calculate the sum of all the integers. 3. Count the number of integers. 4. Calculate the arithmetic mean by dividing the sum by the count.

Here's an example implementation of the function `P` that takes the file name as a parameter and returns the arithmetic mean as a `DOUBLE`:

```pascal FUNCTION P(NAME: STRING): DOUBLE; VAR F: FILE OF INTEGER; Num: INTEGER; Sum: INTEGER; Count: INTEGER; BEGIN Sum := 0; Count := 0; // Open the file ASSIGN(F, NAME); RESET(F); // Read the integers and calculate the sum and count WHILE NOT EOF(F) DO BEGIN READ(F, Num); // Check if the difference between the largest and smallest digit is less than 5 IF (ABS(MAXINTDIGIT(Num) - MININTDIGIT(Num)) < 5) THEN BEGIN Sum := Sum + Num; Count := Count + 1; END; END; // Close the file CLOSE(F); // Calculate the arithmetic mean IF Count > 0 THEN P := Sum / Count ELSE P := 0; END; ```

Please note that the `MAXINTDIGIT` and `MININTDIGIT` functions are not standard Pascal functions. You would need to implement them yourself to find the largest and smallest digit of an integer.

Remember to replace `MAXINTDIGIT` and `MININTDIGIT` with the appropriate functions to find the largest and smallest digit of an integer.

Example usage: ```pascal VAR Mean: DOUBLE; BEGIN Mean := P('filename.txt'); WRITELN('The arithmetic mean is: ', Mean); END. ```

Make sure to replace `'filename.txt'` with the actual name of the file you want to process.

Please let me know if you need any further assistance!

0 0

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

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

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