Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can someone explain this part of code to me?

What does exp=floor(log10(static_cast<double>(n))); mean?

I got the algorithm on internet but I dont get what this part means.

int spatiu (int n)
{
    int exp = floor(log10(static_cast<double>(n)));
    int div;
    while (n != 0)
    {
        div = pow(10.0, exp);
        cout << n / div << " ";
        n %= div;
        exp--;
    }
    cout << endl;
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

here

floor(log10(static_cast<double>(n)));

floor() function is used to take value in round off example 12.6 means floor value is 11.

static_cast<double>(n) is used here to "n" typecast in double. and log10() is used to take log10(n) of a number.

summary is floor(log10(static_cast<double>(n))); is used to calculate the length of number-1; for example n= 153, then function return 2 as a output.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading