Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int prost(int a) {
- int flag(1);
- if (a == 1) {
- return 0;
- }
- for (int i = 2; i < a/2 ; i++) {
- if (a % i == 0) {
- flag = 0;
- break;
- }
- }
- return flag;
- }
- int main()
- {
- ifstream f("C:\\Users\\knop2\\source\\repos\\экзфайл\\input.txt");
- if (f)
- {
- int a, z(0);
- vector<int>out;
- ofstream g("C:\\Users\\knop2\\source\\repos\\экзфайл\\\output.txt");
- while (!f.eof())
- {
- f >> a;
- if (prost(a) == 1) {
- out.push_back(a);
- }
- }
- for (int i = 0; i < out.size(); i++) {
- for (int j = 0; i < out.size() - 1; j++) {
- if (out[j] >= out[j + 1]) {
- swap(out[j], out[j + 1]);
- }
- }
- }
- for (int i = 0; i < out.size(); i++)
- cout << out[i];
- for (int i = 0; i < out.size(); i++) {
- if (z == 4) {
- g << out[i] << '\n';
- z = 0;
- }
- else {
- g << out[i] << ' ';
- }
- z++;
- }
- g.close(); f.close();
- }
- else
- cout << "ERROR!";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement