/
Feltel
/
Zadania
Обзор
Документация
Войти
/
Feltel
/
Zadania
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
untitled3.cpp
65 строк
2 KB
Feltel
upload files
28 окт 2025, 07:36
28 окт 2025, 07:36
244caa6
Код
Авторство
О чём код?
#include <iostream> #include <fstream> #include <cstdlib> #include <ctime> using namespace std; void generateRandomNumbers(const string& filename, int count) { setlocale(LC_ALL, ""); ofstream outFile(filename); if (!outFile) { cerr << "Ошибка при открытии файла для записи!" << endl; return; } for (int i = 0; i < count; ++i) { int randomNumber = rand() % 100; outFile << randomNumber << endl; } outFile.close(); } void filterNumbers(const std::string& inputFile, const string& outputFile, int m, int n) { ifstream inFile(inputFile); ofstream outFile(outputFile); if (!inFile) { cerr << "Ошибка при открытии файла для чтения!" << endl; return; } if (!outFile) { cerr << "Ошибка при открытии файла для записи!" << endl; return; } int number; while (inFile >> number) { if (number % m == 0 && number % n != 0) { outFile << number << endl; } } inFile.close(); outFile.close(); } int main() { srand(static_cast<unsigned int>(time(0))); setlocale(LC_ALL, ""); const string inputFile = "F.txt"; const string outputFile = "G.txt"; int count = 100; int m, n; cout << "Введите значение m: "; cin >> m; cout << "Введите значение n: "; cin >> n; generateRandomNumbers(inputFile, count); filterNumbers(inputFile, outputFile, m, n); cout << "Файлы успешно обработаны." << endl; return 0; }