# my nifty little exponent program

• 03-18-2002
maxwell_edison
my nifty little exponent program
hello all. I'm a beginning programmer and I thought that I would try to write a program that would take a digit and raise it to a large number. It works pretty well and all, but it starts returning all zeros for number larger than 4^15. I would appreciate it if anyone could tell me why? Thank you

int mypow=0;
int diff=0;
int base=0;
int carry=0;
int lnumber[99]={0};

///////////////////////////////////////////////

void remain(int fnum, int fnum2)
{
for (int k=0; k<100; k+=10)
{
if (fnum*fnum2>=k)
{diff=fnum*fnum2-k;carry=k/10;break;}
}

}
//////////////////////////////////////////////

void mult(int farr[], int foper)
{
for (int i=99; i>0; i--)
{
remain(farr[i], foper);
}
}
////////////////////////////////////////////

void power(int farr2[],int fexp,int fbase)
{
for (int i=1;i<fexp;i++)
{mult(farr2,fbase);}
}
////////////////////////////////////////

#include <iostream>
using namespace std;

int main()
{
cout<<"enter base";
cin>>base;
cout<<"enter exponent";
cin>>mypow;
lnumber[99]=base;
power(lnumber,mypow,base);
for (int i=0;i<100;i++) {cout<<lnumber[i];}
return 0;
}
• 03-18-2002
SilentStrike
4^15 = 2^30. Your machine has integers that are 32 bits.. so they have a total of 2^32 possible values, once you hit 4^16, or 2^32, you just exceeded the maximum. You can try to use unsigned ints, which should let you store 4^16 (but no negative numbers)... but there is no huge difference.
• 03-18-2002
maxwell_edison
thank you for your help, but i dont think that is the problem. The digits are stored in the array lnumber...so it should be able to handle 100 digits right? since only basic multiplication and addition are being performed on each element
• 03-18-2002