Search
 
SCRIPT & CODE EXAMPLE
 

CPP

power of number

double Pow(double x, int n) 
{
  double ans=1.0;
  while(d>0)
  {
    if(d&1==1)
      ans*=x;
    d>>=1;
    x*=x;
  }
  return ans;
}
Comment

power of a number

#include <iostream>
using namespace std;

long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}

int main()
{
    long long x = 5;
    long long y = 16;
    
    cout << "Power is " << binpow(x, y);
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: cpp while 
Cpp :: letter occurrence in string c++ 
Cpp :: print pattern and space in cpp 
Cpp :: how to make Dijkstra in c++ 
Cpp :: c++ erase remove 
Cpp :: how can we create 4 digit random number in c++ 
Cpp :: zero fill in c++ 
Cpp :: word equation numbers 
Cpp :: c function as paramter 
Cpp :: how to print in new lines in C++ 
Cpp :: inserting element in vector in C++ 
Cpp :: c++ program to generate all the prime numbers between 1 and n 
Cpp :: c++ access second last element of vector 
Cpp :: vector iterating in c++ 
Cpp :: how to create a file in c++ 
Cpp :: access last element of set c++ 
Cpp :: inheritance example in C plus plus 
Cpp :: passing custom function in sort cpp 
Cpp :: How to split a string by Specific Delimiter in C/C++ 
Cpp :: int max in c++ 
Cpp :: converting decimal to binary in cpp 
Cpp :: loop execution descending order in c++ 
Cpp :: power in c++ 
Cpp :: vector::at() || Finding element with given position using vector in C++ 
Cpp :: opengl draw house using glut c++ 
Cpp :: c++ std map initializer list 
Cpp :: c++ swap function 
Cpp :: string c++ 
Cpp :: create vector of specific size c++ 
Cpp :: abs c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =