SPOJ problem - The last digit of a number to a power
As you have probably noticed, this is not efficient because you have a loop running exponent times (which could be over 2 billion). The way to make this more efficient is not to make your code faster, but to choose a better algorithm.

I'm not going to tell you outright what the answer is, but do the following. Add some output to your loop:

        for(i=1;i&lt;=exponent;i++)
        {
            digit=(base*digit)%10;
            printf("digit = %d\n", digit);
        }


and then run your program for some (small) sample inputs. You should notice a pattern. The key is to identify the pattern and use it to avoid running the loop a billion times.