Advertisement
malixds_

Untitled

Nov 8th, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {   
  7.     setlocale(LC_ALL, "ru");
  8.     ofstream f;
  9.     int arr[10];
  10.     int sum = 0,
  11.         n = 0;
  12.     f.open("C:\\sum.txt", ios::in);
  13.     if (f.is_open()) {
  14.         for (int i = 0; i < 10; i++) {
  15.             cout << "Введите " << i + 1 << " число: ";
  16.             cin >> arr[i];
  17.             f << arr[i] << ' ';
  18.         }
  19.         f.close();
  20.  
  21.  
  22.         ifstream fin;
  23.         fin.open("C:\\sum.txt");
  24.         if (!fin) {
  25.             cout << "Ошибка открытия файла" << '\n';
  26.         }
  27.         while (fin >> n) {
  28.             sum += n;
  29.         }
  30.         cout << "Сумма = " << sum;
  31.  
  32.         fin.close();
  33.         return 0;
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement