Untitled
unknown
c_cpp
a year ago
895 B
8
Indexable
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inputFile("dane.txt");
int tab[30];
int size = 0;
if (!inputFile.is_open())
{
cerr << "Nie mozna otworzyc pliku dane.txt!" << endl;
return -1;
}
else
{
int number;
while(inputFile >> number)
{
tab[size] = number;
++size;
}
inputFile.close();
}
ofstream outputFile("wynik.txt");
if (!outputFile.is_open())
{
cerr << "Nie mozna otworzyc pliku wynik.txt!" << endl;
return 0;
}
else
{
for (int i = 0; i < size; ++i)
{
if (tab[i] % 10 == 0 || tab[i] % 10 == 3 ||
tab[i] % 10 == 8 || tab[i] % 10 == 9)
{
outputFile << tab[i] << '\n';
}
}
cout << "Liczby, ktorych cyfry jednosci koncza sie na 0, 3, 8 lub 9 "
<< "zapisano do pliku wynik.txt" << endl;
outputFile.close();
}
return 0;
}Editor is loading...
Leave a Comment