Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int prost(int a) {
  8. int flag(1);
  9. if (a == 1) {
  10.  
  11. return 0;
  12. }
  13. for (int i = 2; i < a/2 ; i++) {
  14. if (a % i == 0) {
  15. flag = 0;
  16. break;
  17. }
  18. }
  19. return flag;
  20. }
  21. int main()
  22. {
  23.  
  24. ifstream f("C:\\Users\\knop2\\source\\repos\\экзфайл\\input.txt");
  25. if (f)
  26. {
  27. int a, z(0);
  28. vector<int>out;
  29.  
  30. ofstream g("C:\\Users\\knop2\\source\\repos\\экзфайл\\\output.txt");
  31. while (!f.eof())
  32. {
  33. f >> a;
  34. if (prost(a) == 1) {
  35. out.push_back(a);
  36. }
  37. }
  38. for (int i = 0; i < out.size(); i++) {
  39. for (int j = 0; i < out.size() - 1; j++) {
  40. if (out[j] >= out[j + 1]) {
  41. swap(out[j], out[j + 1]);
  42. }
  43. }
  44. }
  45. for (int i = 0; i < out.size(); i++)
  46. cout << out[i];
  47. for (int i = 0; i < out.size(); i++) {
  48. if (z == 4) {
  49. g << out[i] << '\n';
  50. z = 0;
  51. }
  52. else {
  53. g << out[i] << ' ';
  54. }
  55. z++;
  56.  
  57. }
  58. g.close(); f.close();
  59. }
  60. else
  61. cout << "ERROR!";
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement