Answers for "c++ power operator"

C++
20

pow 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;
}
Posted by: Guest on January-10-2020
1

pow in cpp header file

#include<cmath> //header file for pow fun


   pow(a,b)    // a^b
Posted by: Guest on July-12-2020
0

c++ power operator

#include <iostream>
#include <cmath>

using std::cout;
using std::cin;

int main() {
  int base, exponent;
  cout << "Enter Base";
  cin >> base;
  cout << "Enter Exponent";
  cin >> exponent;
  cout << pow(base, exponent);
}

// Enter Base : 2
// Enter Exponent : 4
// 16
Posted by: Guest on July-08-2021
0

powers of 2 in cpp

// 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;
}
Posted by: Guest on June-04-2020

Browse Popular Code Answers by Language