How do you use pow function in c?

1 answer

Answer

1117853

2026-07-20 16:15

+ Follow

Either you can use the pre defined function "pow" in the <math.h> header file OR you can make a user defined function to do the same operation.

1.Using the pre defined function in <math.h> :

The function is a of datatype double and accepts only values in double. So, prototype declaration is:

double pow(double x,double y);

Pass the values to the function and it'll return the value of xy. In the calling function it can be declared as:

double power=pow(x,y);

2.USER DEFINED FUNCTION:

double power(double x,int y);

int main()

{

double x,result;

int y;

cout<<"\nEnter the base: "<<;

cin>>x;

cout<<"\nEnter the exponential power: ";

cin>>y;

result=power(x,y);

cout<<"The result of x to the power y is: "<<result;

return 0;

}

double power(double x,int y)

{

for(int i=0;i<=y;i++)

{

x*=x;

}

return x;

}

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.