Untitled

 avatar
unknown
c_cpp
a year ago
849 B
4
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