Shirley
8
Q:

power in c++

#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
  double base, exponent, result;		
  base = 3.4;	
  exponent = 4.4;	
  result = pow(base, exponent);		
  cout << base << "^" << exponent << " = " << result;		
  return 0;
}
10
// C program to illustrate 
// power function 
#include <math.h> 
#include <stdio.h> 
  
int main() 
{ 
    double x = 6.1, y = 4.8; 
  
    // Storing the answer in result. 
    double result = pow(x, y); 
    printf("%.2lf", result); 
  
    return 0; 
} 
2
/* pow example */
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */

int main ()
{
  printf ("7 ^ 3 = %f\n", pow (7.0, 3.0) );
  printf ("4.73 ^ 12 = %f\n", pow (4.73, 12.0) );
  printf ("32.01 ^ 1.54 = %f\n", pow (32.01, 1.54) );
  return 0;
}
0
// If not using any extra libraries
// Powers of 2. If finding 2^n
int main() {
  int ans = 1 >> n;
}
// Suppose we want to find x ^ y
void power(int x, int y) {
  int ans = 1;
  for (int i = 0; i < y; i++) {
    ans *= x;
  }
  return ans;
}
0

New to Communities?

Join the community