알고리즘

알고리즘

February 19, 2020 ( last updated : February 18, 2020 )
algorithm

https://github.com/gmm117/gmm117.github.io


Abstract

    Algorithm 특징

bool isPrime(int number)
{
    number = abs(number);

    if(number==0 && number==1)
    {
        return false;
    }

    int divisor;
    for(divisor=number/2; number%divisor != 0; --divisor)
    ;

    return divisor==1;
}

int main(int argc, char* argv[])
{
    list<int> coll;

    for(int i=24; i<=30; ++i) {
        coll.push_back(i);
    }

    list<int>::iterator pos;

    pos = find_if(coll.begin(), coll.end(), isPrime);

    if(pos != coll.end()) {
        cout << *pos << " is first prime number found" << endl;
    }
    else {
        cout << "no prime number found" << endl;
    }

    return 0;
}

Originally published February 19, 2020
Latest update February 18, 2020

Related posts :