can anyone go through it?

Recommended Answers

All 4 Replies

What do you have so far?

Finding a number's cube is simply a matter of multiplying it by itself three times:

double cube(double x)
{
    return x * x * x;
}

Are you sure you didn't mean the cube root?

for the root you can use the pow function

#include<cmath>
using namespace std;


double temp = pow(27.0,1.0/3);

Cube for integers without multiplication:

static int cube(int x)
        {
            int s = 0, c = 0;
            for (int i = 0; i < x; i++)
            {
                s += x;
            }
            for (int i = 0; i < x; i++)
            {
                c += s;
            }
            return c;
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.