355 - The Bases Are Loaded (math numbers conversion)
No, you don't need to convert to base 10. Base 10 is in fact quite slow to operate with, as it is in no way a "native" base for computers, which store integers in binary format.

Let's do the math. Assume you need to convert four digit number from base a to base b. Let x_i denote the digit of the number in base a and y_i the digit in base b:

In base a the number is:

x1*a^3 + x2*a^2 + x3*a^1 + x4*a^0 = ((x1*a + x2)*a + x3)*a + x4


In base b it becomes:

y1*b^3 + y2*b^2 + y3*b^1 + y4*b^0 = ((y1*b + y2)*b + y3)*b + y4


The right side of these equations suggests an algorithm idea: to convert a number to binary format from a string s in base a, start with zero, and in each step multiply the number so-far with a and add the next digit. This requires only one multiplication per loop, not two, like in your approach (although that's not likely the reason why your code is too slow.)

int len = strlen(s);
int i;
unsigned long long number = 0;

for (i = 0; i &lt; len; ++i) {
        unsigned digit;
        if (s[i] &gt;= '0' &amp;&amp; s[i] &lt;= '9') {
                digit = s[i] - '0';
        } else {
                digit = s[i] - 'A' + 10;
        }
        number = number * a + digit;
}


You had the rest of it already: adding for completeness. For conversion to base b, in each step divide by b.

const char digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

char result[50];
/* Note the end condition here: stop when the number becomes zero */
for(i = 0; number != 0; ++i) {
        unsigned digit = number % b;
        number /= b;
        result[i] = digits[digit];
}


Now result contains the digits backwards. To print them in order:

for (; i &gt;= 0; --i) {
        putchar(result[i]);
}


Other minor performance notes


Don't call strlen() twice - there's no need to do it more than once anyway, but if there was, you could cache the result and pass as a parameter.
The code in main that determines whether the input string is acceptable is too complex: no need to do the conversion here, just check if each digit is in the acceptable range.


Unrelated notes about readability:


instead of this:


base = (base &gt; a[i]-'0') ? base : a[i]-'0';

suggest using this:

base = max(base, a[i] - '0');



Avoid variable names like l - easy to confuse with 1.
Use const before read-only variabes (such as the array of digits).