Vla_DOS

Untitled

Jun 17th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <time.h>
  4. #include <chrono>
  5. #include <fstream>
  6. #include <sstream>
  7. #include <algorithm>
  8. #include <string>
  9.  
  10. using namespace std;
  11.  
  12. int main() {
  13.     setlocale(LC_CTYPE, "");
  14.     int num;
  15.     cout << "Кiлькiсть елементiв: ";
  16.     cin >> num;
  17.     int* A = new int[num];
  18.  
  19.     for (int i = 0; i < num; i++) {
  20.         A[i] = rand() % 43 - 30;
  21.     }
  22.     int sum = 0;
  23.  
  24.     for (int i = 0; i < num; i++) {
  25.         if(A[i] > 0)
  26.             sum += A[i];
  27.     }
  28.     for (int i = 0; i < num; i++) {
  29.         cout << A[i] << "\t";
  30.     }
  31.     fstream f;
  32.     f.open("input.txt", fstream::in | fstream::out);
  33.  
  34.     if (f.is_open() == NULL)
  35.     {
  36.         cout << "error!";
  37.         return -1;
  38.     }
  39.     f << sum;
  40.     f.close();
  41.     std::string line;
  42.  
  43.     std::ifstream in("input.txt");
  44.     if (in.is_open())
  45.     {
  46.         while (getline(in, line))
  47.         {
  48.             cout << "\nРезультат: " << line << endl;
  49.         }
  50.     }
  51.     in.close();
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment