CppBuzz.com
  
Home C C++ Java Python Perl PHP SQL Javascript Linux Forum

You are here : Home » Solved Programs on C++ » C++ program to find power of any number

C++ program to find power of any number without using pow() function

#include<iostream>
using namespace std;

unsigned long int integerPower(int base, unsigned int power)
{
unsigned long int val=  base;

for(unsigned long int i = 0; i< power-1; i ++)
{
  val = val * base; 
}

return val;
}

int main()
{
int base;
unsigned int power;
unsigned long int val = 0;

cout<<"\n Enter base (non zero) : ";
cin>>base;

cout<<"\n Enter power (positive) : ";
cin>>power;

val = integerPower(base, power);

cout<<"\n Result is : "<< val;

return 0;
}