Sum of digits in a^b
Some general remarks:


Use more and consistent spacing, e.g.

digits[i]=temp%10;


should be

digits[i] = temp % 10;

Define variables only at the scope where they are used, e.g. carry 
is used only inside the while (b--) { ... } loop.
Move the actual computation to a separate function so that main() becomes 
shorter. That makes it also easier to add test cases.
Assuming that int has (at least) 32 bits (which is the case on all modern
platforms), there is no need to use long long at all in your code.
There is no need to treat the case b = 0 separately. a ^ 0 is 1, and that can be covered with the general case if you
start with digits[] = { 1 } instead of digits[] = { a }.


The performance can be increased by storing more than a single decimal
digit in each array element digits[i]. Since 10^9 &lt; 2^31, you can store
8 decimal digits in digits[i] and digits[i] * a + carry will still not
overflow.

Your program would then look like this:

const int BASE = 100000000; //  10^8

int powerDigitSum(int a, int b) {
    int digits[4000] = { 1 } ;
    int len = 1;

    while (b-- &gt; 0) {
        int carry = 0;
        for (int i = 0; i &lt; len; i++) {
            int temp = digits[i] * a + carry;
            digits[i] = temp % BASE;
            carry = temp / BASE;
        }
        if (carry != 0) {
            digits[len++] = carry;
        }
    }

    int sum = 0;
    for (int i = 0; i &lt; len; i++) {
        int d = digits[i];
        while (d &gt; 0) {
            sum += d % 10;
            d /= 10;
        }
    }
    return sum;
}

int main() {
    int test, a, b;
    scanf("%d",&amp;test) ;
    for (int i = 0; i &lt; test; i++) {
        scanf("%d %d",&amp;a,&amp;b) ;
        int sum = powerDigitSum(a, b) ;
        printf("Case %d: %d\n", i, sum) ;
    }
    return 0 ;
}


Your original algorithm corresponds to BASE = 10. Using BASE = 100000000
instead reduced the computation time for a=9, b=4000 from 0.095 seconds
to 0.014 seconds on my computer.

If that is not sufficient, you can use (unsigned) long long for the digits[] array  and work with an even larger BASE.