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. Максимальный элемент последовательности.
int num; float max = INT_MIN, count = 0, sum = 0;
if (num > max) max = num;
if (max == INT_MIN) cout << "Error." << endl; else
cout << "Maximum element: = " << max << endl;
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;
}