2 to 24 Powers Challange

Hİ.
I did not just want to use Math.Pow(2,24). So I found this;

int x = 1;
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log(Power(2, 24));
    }

    int Power(int a, int b)
    {
        for (int i = 0; i < b; i++)
        {
            x = a * x;
        }
        return x;
    }

Yeah, I am sad I forgot most things… Could not come up with the solution all by myself =(

1 Like

Just keep it up and you’ll be a master in no time

1 Like

Here is more… khm… specific :laughing:

        static void Main(string[] args)
        {
            Console.WriteLine(Power(2,24));
        }

        static int Power(int a, int b)
        {
            int x = 1;
            int i = 0;
            do
            {
                x *= a;
                i++;
            }
            while (i < b);
            return x;
        }

Hi!, I have found three different ways to do this:

  1. Using System.Math.Pow, we have to work with doubles

image

  1. Using Mathf.Pow, we have to work with floats

image

  1. I have found a way to do it by myself, for this time I’ve decided to do it with ints

image

image

Privacy & Terms