diff --git a/lab3.cpp b/lab3.cpp new file mode 100644 index 0000000..2afad2d --- /dev/null +++ b/lab3.cpp @@ -0,0 +1,65 @@ +#include +#include +using namespace std; + +int main() +{ + size_t num, po, i; + double max, min, m = 0, le, ri; + cout << "num="; + cin >> num; + cout << "po="; + cin >> po; + vector mas(num); + vector ch(po); + for (i = 0; i < num; i++) + { + cout << "mas [" << i << "]="; + cin >> mas[i]; + } + cout << endl; + max = mas[0]; + min = mas[0]; + for (i = 1; i < num; i++) + { + if (max < mas[i]) + max = mas[i]; + if (min > mas[i]) + min = mas[i]; + } + le = min; + ri = le + (max - min) / po; + int kol = 0; + while (kol < po - 1) + { + for (i = 0; i < num; i++) + { + if (le <= mas[i] && ri > mas[i]) + ch[kol]++; + } + if (ch[kol] > m) + m = ch[kol]; + kol++; + le = ri; + ri = le + (max - min) / po; + } + for (i = 0; i < num; i++) + { + if ((ri <= mas[i] && le < mas[i]) || (le <= mas[i] && ri > mas[i])) + ch[kol] ++; + if (ch[kol] > m) + m = ch[kol]; + } + for (i = 0; i < po; i++) + { + int d = m - ch[i]; + if (d != 0) + for (int j = 0; j < d; j++) + cout << " "; + for (size_t j = 0; j < ch[i]; j++) + cout << "*"; + cout << "|" << ch[i]; + cout << endl; + } + return 0; +} \ No newline at end of file