C/C++
СРОЧНО ПОЖАЛУЙСТА ПОМОГИТЕ
Сформировать массив b записав в негг элементы массива а с нечетными индексами вычислить среднее арифметическое элементов массива b и иудалить из него максимальный минимальный и пятый элемент. НА С++, БЛОК-СХЕМА И ШКОЛЬНЫЙ АЛГОРИТМ ПОЖАЛУЙСТА
#include <iostream>
using namespace std;
void shift(int* beg, int* end) {
int x = *beg;
while (++beg != end) *(beg - 1) = *beg;
*(beg - 1) = x;
}
void show(const char* msg, int* box, int n) {
cout << msg;
for (int i = 0; i < n; ++i) cout << box[i] << ' ';
puts("");
}
int* find(int* box, int n, int x) {
auto end = box + n;
for (auto beg = box; beg != end; ++beg) {
if (*beg == x) return beg;
}
return end;
}
int* max(int* box, int n) {
auto end = box + n;
auto mx = *box;
auto ptr = box;
for (auto beg = box + 1; beg != end; ++beg) {
if (*beg > mx) {
mx = *beg;
ptr = beg;
}
}
return ptr;
}
int* min(int* box, int n) {
auto end = box + n;
auto mn = *box;
auto ptr = box;
for (auto beg = box + 1; beg != end; ++beg) {
if (*beg < mn) {
mn = *beg;
ptr = beg;
}
}
return ptr;
}
size_t erase(int* box, int n, int* target) {
shift(target, box + n);
return n - 1;
}
double average(int* box, int n) {
double sum = 0.0;
for (int i = 0; i < n; ++i) sum += box[i];
return sum / n;
}
void transfer(int* dest, int* src, int n) {
for (int i = 1, j = 0; i < n; i += 2, ++j) {
dest[j] = src[i];
}
}
int main() {
int a[]{ 50, 17, 42, 39, 94, 15, 63, 72, 28, 59, 43, 19, 55, 74, 31, 68 };
size_t m = size(a);
size_t n = m >> 1;
int* b = new int[n];
transfer(b, a, m);
show("a: ", a, m);
show("b: ", b, n);
double avg = average(b, n);
cout << "average: " << avg << '\n';
n = erase(b, n, b + 4);
show("-5: ", b, n);
int* pmx = max(b, n);
n = erase(b, n, pmx);
show("-max: ", b, n);
int* pmn = min(b, n);
n = erase(b, n, pmn);
show("-min: ", b, n);
delete[] b;
system("pause > nul");
}
using namespace std;
void shift(int* beg, int* end) {
int x = *beg;
while (++beg != end) *(beg - 1) = *beg;
*(beg - 1) = x;
}
void show(const char* msg, int* box, int n) {
cout << msg;
for (int i = 0; i < n; ++i) cout << box[i] << ' ';
puts("");
}
int* find(int* box, int n, int x) {
auto end = box + n;
for (auto beg = box; beg != end; ++beg) {
if (*beg == x) return beg;
}
return end;
}
int* max(int* box, int n) {
auto end = box + n;
auto mx = *box;
auto ptr = box;
for (auto beg = box + 1; beg != end; ++beg) {
if (*beg > mx) {
mx = *beg;
ptr = beg;
}
}
return ptr;
}
int* min(int* box, int n) {
auto end = box + n;
auto mn = *box;
auto ptr = box;
for (auto beg = box + 1; beg != end; ++beg) {
if (*beg < mn) {
mn = *beg;
ptr = beg;
}
}
return ptr;
}
size_t erase(int* box, int n, int* target) {
shift(target, box + n);
return n - 1;
}
double average(int* box, int n) {
double sum = 0.0;
for (int i = 0; i < n; ++i) sum += box[i];
return sum / n;
}
void transfer(int* dest, int* src, int n) {
for (int i = 1, j = 0; i < n; i += 2, ++j) {
dest[j] = src[i];
}
}
int main() {
int a[]{ 50, 17, 42, 39, 94, 15, 63, 72, 28, 59, 43, 19, 55, 74, 31, 68 };
size_t m = size(a);
size_t n = m >> 1;
int* b = new int[n];
transfer(b, a, m);
show("a: ", a, m);
show("b: ", b, n);
double avg = average(b, n);
cout << "average: " << avg << '\n';
n = erase(b, n, b + 4);
show("-5: ", b, n);
int* pmx = max(b, n);
n = erase(b, n, pmx);
show("-max: ", b, n);
int* pmn = min(b, n);
n = erase(b, n, pmn);
show("-min: ", b, n);
delete[] b;
system("pause > nul");
}
Musleem Dont Pan1C
А можно это как-то в упрощенном виде?
куда записать решение?
Musleem Dont Pan1C
Можно сюда в виде фото
Артур Комаров
У меня полароид 70-х годов, а что за ШКОЛНЫЙ АЛГОРИТМ?
Похожие вопросы
- С++. Срочно пожалуйста помогите
- Составить программу c++ срочно пожалуйста
- Надо написать программу на с++ СРОЧНО!!!!! ПОЖАЛУЙСТА
- Пожалуйста, помогите написать программу на С++
- Пожалуйста помогите с задачей на С++
- Программа на с++ (нужен код) пожалуйста помогите
- Пожалуйста, помогите с C++
- Пожалуйста помогите написать программу на С++
- Программирование, пожалуйста помогите очень нужно решить
- Всем здарово! Пожалуйста помогите! Кому несложно очень прошу!