Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
849 B
0
Indexable
Never
#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;
}
Leave a Comment