• 40 баллов C ++ последовательность состоит из натуральных чисел и завершается числом 0.Определи значении наибольшого элемента последовательности. Вводимые цифры:1,7,9,0.зарание спасибо))​ должно получится,5.66666666667 в результате​

Ответы 1

  • 1. Среднее арифметическое.

    #include "stdafx.h"

    #include <iostream>

    using namespace std;

    int main()

    {

    int  num; float arithm = 0, count = 0, sum = 0;

    cout << "Enter numbers (0 - a sign of the end of input) :  " << endl;

    do

    {

     cin >> num;

     if (num != 0)

     {

      count++;

      sum += num;

     }

    } while (num != 0);

    arithm = sum / count;

    if (sum == 0) cout << "Error." << endl; else  

    cout << "The arithmetic mean of these numbers = " << arithm << endl;

    system ("pause");

    return 0;

    }

    2. Максимальный элемент последовательности.

    #include "stdafx.h"

    #include <iostream>

    using namespace std;

    int main()

    {

    int  num; float max = INT_MIN, count = 0, sum = 0;

    cout << "Enter numbers (0 - a sign of the end of input) :  " << endl;

    do

    {

     cin >> num;

     if (num != 0)

     {

      if (num > max) max = num;

     }

    } while (num != 0);

    if (max == INT_MIN) cout << "Error." << endl; else

    cout << "Maximum element: = " << max << endl;

    system ("pause");

    return 0;

    }

  • Добавить свой ответ

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years