Advertisement
Dorreli

Untitled

Jan 19th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fstream>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9. setlocale(0, "Rus");
  10. ifstream file("J:\\Универ\\Программирование\\Практика_txt\\z_2.txt");
  11. if (file.is_open())
  12. {
  13. cout << "Файл открыт" << endl;
  14. const int n = 30;
  15. int zero = 0, p = 0, m = 0;
  16. int F[n], A[n], D[n];
  17. cout << "Массив F:" << endl;
  18. for (int i = 0; i < n; i++)
  19. {
  20. file >> F[i];
  21. cout << "F[" << i << "] = " << F[i] << endl;
  22. if (F[i] == 0) zero++;
  23. if (F[i] < 0)
  24. {
  25. A[m] = F[i];
  26. m++;
  27. }
  28. if (F[i] > 0)
  29. {
  30. D[p] = F[i];
  31. p++;
  32. }
  33. }
  34. cout << "Массив отрицательных чисел: ";
  35. for (int i = 0; i < m; i++)
  36. {
  37. cout << A[i]<<" | ";
  38. }
  39. cout << endl << "Массив положительных чисел: ";
  40. for (int i = 0; i < p; i++)
  41. {
  42. cout << D[i] << " | ";
  43. }
  44. cout << endl << "Количество нулей: " << zero << endl;
  45. system("pause");
  46. return 0;
  47. }
  48. else
  49. {
  50. cout << "Файл не открыт" << endl;
  51. system("pause");
  52. return 0;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement