Home / Expert Answers / Computer Science / c-code-using-functions-currently-i-have-everything-written-in-the-main-i-just-need-to-use-functi-pa622

(Solved): C++ Code using functions; currently I have everything written in the main, I just need to use functi ...



C++ Code using functions; currently I have everything written in the main, I just need to use functions instead of writing everything in the main. I have listed the function below.

 

Function need to use:

/**

* Finds the first factor of n great than or equal to f.

* @param n number whose factor can  be found

* @param f the lower bound on the factor to be found

* @return the smallest factor of n that is greater than or equal to f.

*/

/**long findFactor(long n, long f);

 

/**

* Determines the multiplicity of f as a factor of residual.

* The residual remains the same and the count is 0 if f < 2.

* @param residual a number whose factor is to be determined

* @param f a factor of residual; residual is updated with the

* number left after all the factors of f in the residual are

* extracted; that is, residual = residual / f^count, where count

* is the largest integer multiplicity of f as a factor of

* the current residual

* @param count the largest multiplicity of f as a factor of residual

*/

 

 

void factorCount(long &residual, long f, long& count);

 

/**

* Generates the string representation of the prime factorization of a

* number, counts the number of prime factors that the number has

* without honoring multiplicity, and counts the number of prime

* factors that the number has honoring mulitiplicity.

* @param n a number to be decomposed into a product of prime factors

* @param fStr a string representation of the prime decomposition of n;

* it holds "nan" is n is less than 2.

* @param litOhm number of prime factors of n, not honoring multiplicity.

* @param bigOhm the number of prime factors of n, honoring multiplicity.

*/

void factorize(long n, string& fStr, long& litOhm, long& bigOhm);

 

 

 

This is my code now with everything in the main:

#include <iostream>

 

#include <cmath>

using namespace std;

int main()

{

    int n;

    cout<<"Enter a positive integer -> ";

    cin>>n;

    if (n < 2)

       cout<<"There are no pirmes in "<<n<<"."<<endl;

    else

    {

        cout<<"FactorInteger["<<n<<"] = ";

        int i = 2, count, omega = 0, big = 0;

        int residual = n;

        while (i <= sqrt(residual) && residual % i != 0)

           i++;

        if (i > sqrt(residual))

           i = residual;

        cout<<i;

        omega++;

        count = 0;

        while (residual % i == 0)

        {

            count++;

            residual = residual / i;

        }

        big += count;

        bool root = true;

        if (count > 1)

        {

            root = false;

        }

        if (count > 1)

           cout<<"^"<<count;

        while (i < sqrt(residual))

        {

            i++;

            while (residual % i != 0)

               i++;

            cout<<" x "<<i;

            omega++;

            count = 0;

            while (residual % i == 0)

            {

                count++;

                residual = residual / i;

            }

            big += count;

            if (count > 1)

                cout<<"^"<<count;

        }

        if (residual > 1)

        {

            cout<<" x "<<residual;

            omega++;

            big++;

        }

        cout<<endl;

        cout<<"littleOmega("<<n<<") = "<<omega<<endl;

        cout<<"bigOmega("<<n<<") = "<<big<<endl;

        cout<< std::boolalpha << "Squarefree("<<n<<")? = "<< root <<endl;

    }

    return 0;

}



We have an Answer from Expert

View Expert Answer

Expert Answer


#include #include using namespace std; /** * Finds the first factor of n great than or equal to f. * @param n number whose factor c
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe