...

View Full Version : Power Function



Adeel.Rekhi
01-14-2012, 12:58 PM
#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 power is set as 0, its not generating the result.
Help me out....

Adeel.Rekhi
01-14-2012, 07:08 PM
I got it myself.....:D

Spookster
01-14-2012, 09:23 PM
In the future always post code using code or php tags. Read here for more info
http://www.codingforums.com/misc.php?do=bbcode#code



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum