r/programming • • May 08 '15

Five programming problems every Software Engineer should be able to solve in less than 1 hour

https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
2.5k Upvotes

2.1k comments sorted by

View all comments

Show parent comments

-1

u/kakaroto_BR May 08 '15
int total = 1;
for (int i = 0; i < operationCount; ++i) {
    total *= 3;
}

Why not

total = total * operationCount * 3;

4

u/Komputer9 May 08 '15

I don't think that would work? Basically I'm trying to do:

int total = 3 ^ operationCount; // i.e. 3 to the power 8 = 6561

But C doesn't have an integer power operator (apparently the recommended alternative is to use pow and convert it back to an int from the double it returns, but I wanted to keep it more pure).