Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "ru");
- ofstream f;
- int arr[10];
- int sum = 0,
- n = 0;
- f.open("C:\\sum.txt", ios::in);
- if (f.is_open()) {
- for (int i = 0; i < 10; i++) {
- cout << "Введите " << i + 1 << " число: ";
- cin >> arr[i];
- f << arr[i] << ' ';
- }
- f.close();
- ifstream fin;
- fin.open("C:\\sum.txt");
- if (!fin) {
- cout << "Ошибка открытия файла" << '\n';
- }
- while (fin >> n) {
- sum += n;
- }
- cout << "Сумма = " << sum;
- fin.close();
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement