// PascalABC.NET 3.1, сборка 1230 от 27.04.2016 begin var s:=ReadLines('in.txt').ToArray; var n:=StrToInt(s[0]); var a:=s[1].ToWords.Select(e->StrToInt(e)).ToArray; var f:=OpenWrite('out.txt'); Writeln(f,n,' - (кол-во чисел)'); foreach var e in a do Write(f,e,' '); Writeln(f); Writeln(f,'Среднее значение четных ', a.Where(x->x.IsEven).Average); Writeln(f,'Среднее значение нечетных ', a.Where(x->x.IsOdd).Average); f.Close end.
Возможный вариант в C++ #include <iostream> int main() { using namespace std; int N; cout << "Enter N: "; cin >> N; int num; int max = 1; int i; for (i = 0; i < N; ++i) { cout << "Enter #" << i + 1 << " number: "; cin >> num; if ((num - 9) % 10 != 0 && num % 3 == 0) { max = num; break; } } for (int j = i + 1; j < N; ++j) { cout << "Enter #" << j + 1 << " number: "; cin >> num; if ((num - 9) % 10 != 0 && num % 3 == 0) if (num > max) max = num; } if (max != 1) cout << "Max number div by 3 and don't end 9: " << max << endl; else cout << "No numbers div by 3 and don't end 9" << endl; return 0; }
Ответить на вопрос
Поделитесь своими знаниями, ответьте на вопрос:
Найти количество элементов массива целых чисел из 20 элементов, заполнненного с клавиатуры, меньших среднего арифметического элементов массива Очень
/** libraries */
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
/** libraries */
using namespace std;
/** defines */
#define ll long long
#define ld long double
#define yes cout << "YES" << "\n"
#define no cout << "NO" << "\n"
/** defines */
int a[20];
void solve(){
ld sum = 0;
for(auto i: a)
sum += i;
ld av = sum / 20;
int res = 0;
for(auto i: a)
if(i < av)
res++;
cout << res;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
for(int i = 0; i < 20; i++)
cin >> a[i];
solve();
}