Untitled
unknown
c_cpp
2 years ago
849 B
7
Indexable
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool isPrime(int a)
{
if (a <= 1)
{
return false;
}
for (int i = 2; i * i <= a; i++)
{
if (a % i == 0)
{
return false;
}
}
return true;
}
int main()
{
ifstream file("foo.txt");
if (!file.is_open())
{
cout << "ERORR" << endl;
return 1;
}
string filename = "foo.txt";
int n, count = 0, primeCount = 0;
while (file >> n)
{
count++;
if (isPrime(n))
{
primeCount++;
}
}
file.close();
cout << "name faila: " << filename << endl;
cout << "kolvo chisel: " << count << endl;
cout << "kolvo prostih chisel: " << primeCount << endl;
return 0;
}Editor is loading...
Leave a Comment