C++ Programming Code Examples C++ > Mathematics Code Examples For Calculate Power of any number, multiply particular number by itself on the basis of power. For Calculate Power of any number, multiply particular number by itself on the basis of power. Suppose you want to calculate 2^3 is 2*2*2=8. For calculating the power of any number user have four possibilities to input values. Value of power is +ve Value of Power is -ve Value of Base is +ve Value of Base is -ve Value of power is 0 This code only work for when we input +ve power, +ve base value, -ve base value. But it's not work when we enter -ve power value. #include<iostream.h> #include<conio.h> void main() { int b,p,i,pow=1; clrscr(); cout<<"Enter base and power: "; cin>>b>>p; for(i=p;i>0;i--) { pow=pow*b; } cout<<"power is: "<<pow; getch(); }