# Thread: Quick Question Regarding Variable Types

1. ## Quick Question Regarding Variable Types

Hello,

I wrote the function:

int topower(int base, int pwr) {
int topow = 1;
long int amt = base;
while ( topow < pwr ) {
amt = amt * base;
topow++;
}
if ( pwr == 0 ) { amt = 1; }
printf("\n%d:(%d)--%d--", base, pwr, amt);
return amt;
}

since pow() didn't seem to like me for some reason =)
problem is, when i try doing 10^10 (10000000000) I get "1410065408" in printf(). I assume that I'm using an incorret variable type?

Thanks,
Drek

2. USE

unsigned long

NOT

long int

AND CHANGE

amt = amt * base TO amt *= base;

*All integral types are signed meaning they go both ways

EXAMPLE............

For byte, from -128 to 127

UNSIGNED

For unsigned byte, 256 //one-way, either positive or neg is now double capacity

*All the standard math types operate the same way*

3. Perhaps this helps a little bit. But note that if you really want to work with huge numbers, you cannot do this. There is a thread in the C-board discussing working with huge numbers.

Code:
```unsigned long topower (unsigned long base, unsigned long pwr)
{
unsigned long topow = 1;
unsigned long amt = base;

if (pwr == 0)
amt = 1;
else
{
while (topow++ < pwr)
amt *= base;
}

printf("\n%d:(%d)--%d--", base, pwr, amt);
return amt;
}```