Вопрос задан 16.10.2018 в 08:53. Предмет Информатика. Спрашивает Королева Оля.

Вычислить среднее арифметическое N целых чисел (N<=1000, числа <=50000). Исходный файл

text.in, в котором в первой строке указано N, а затем в столбик записано соответствующее количество чисел. Результат записать в файл text.out. Ответ округлить до сотых. Перед тем, как решать задачу создайте в рабочей папке текстовый файл text.in, в котором в первой строке указываем число N (например, 5), а далее в столбик набираем соответствующее количество чисел, одно из которых 50000. Вычисляем и записываем среднее арифметическое
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Лубченков Иван.
Надеюсь, я правильно Вас понял:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    FILE *fIn, *fOut;
    int n, counter=1000;
   
    fIn = fopen("text.in","r");
    fOut = fopen("text.out","w");
   
    fscanf(fIn, "%i", &n);
    for(int i=0; i<n; i++)
    {
        counter=counter+1;
    }
    counter/=n;
    fprintf(fOut,"%i",counter);
}

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

To calculate the arithmetic mean of N integers, you can follow these steps:

1. Read the input from the "text.in" file. The first line of the file should contain the value of N, followed by N integers in subsequent lines. 2. Calculate the sum of all the N integers. 3. Divide the sum by N to get the arithmetic mean. 4. Round the result to two decimal places. 5. Write the arithmetic mean to the "text.out" file.

Here's an example of how you can implement this in Python:

```python # Read input from text.in with open("text.in", "r") as file: lines = file.readlines() N = int(lines[0]) numbers = [int(line.strip()) for line in lines[1:]]

# Calculate the sum of the numbers total = sum(numbers)

# Calculate the arithmetic mean mean = total / N

# Round the mean to two decimal places mean = round(mean, 2)

# Write the result to text.out with open("text.out", "w") as file: file.write(str(mean)) ```

Make sure to create the "text.in" file in your working directory with the appropriate input values before running the code. The result will be written to the "text.out" file.

Please let me know if you need any further assistance!

0 0

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

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

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