Power Function

#include<iostream.h>
#include<conio.h>
int Pow(int , int);
main(){
int num, pow, res;
cout<<"Enter the number u want the power: ";
cin>>num;
cout<<endl
<<"enter the power: ";
cin>>pow;
cout<<endl;
res=Pow(num,pow);
cout<<"The power of "<<num<<" is "<<pow<<" and result is "<<res<<endl;
getch();
}
int Pow(int base, int n)
{
int i,p;
p=base;
if(base==0)
{
return 1;
}
else
{
for(i=1;i<=n-1;i++)
{
p=p*base;
}
return p;
}
}

If the power is set as 0, its not generating yhe result.
Help me out.
Which result is it not generating? What does your code not do that you think it should do?

As an aside, you're using a very old compiler that is not compatible with modern (correct ) C++. I suggest you get a new one, for free, that is.
Last edited on
Topic archived. No new replies allowed.