c exponent code example

Example 1: c power operator

result = (int) pow((double) a,i);

Example 2: power func in c

The function pow() is used to calculate the power raised 
to the base value. It takes two arguments. It returns the
power raised to the base value. It is declared in 
“math.h” header file.

Example 3: 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;
}

Tags:

Misc Example