power functions

+2 Nathan Gonsalves · November 30, 2015
Is there anyway to find out the power of a value without using pow(x,y) function??

Post a Reply

Replies

Oldest  Newest  Rating
0 c student · November 30, 2015
just think about how you would do it by hand
0 Kushal Parikh · December 2, 2015
Use for loop.
0 Ankit Ojha · December 3, 2015
using a user defined function:-

#include<iostream>
using namespace std;
double power(double n, int p=2);
 
double power(double n, int p)
{   int i;
    double result=1;
    for(i=0;i<n;i++)
 {  result=result*p;
 }
 return result;
}
 
int main()
{
  double pwer;
 
  cout<<"enter the value of power : ";
  cin>>pwer;
  cout<<" 2 rasise to power "<<pwer<<" is "<<power(pwer);
return 0;
}
  • 1

C

107,244 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator