Информатика, вопрос задал superrrnatural1 , 7 лет назад

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

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

Ответил angryfukse
0

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;

}

Новые вопросы