I'm using a C++ compiler, but I'm writing C code (if that helps)

There is a string of numbers.

`(-1^(a-1)/2a-1)B^(2a-1)`

A and X are user-specified...

A must be positive, although X might be positive or negative...

in order to decipher this sequence...

I need to utilise exponents/powers, but I have some constraints...

I can't create a new function, utilise recursion, or use pow() (among other advanced math functions that come with cmath or math.h).

There were other comparable queries, however many solutions employed functions and recursion that were not immediately related to this subject.

This is the code that works fine with pow(); I spent a lot of time attempting to adapt it to replace pow() with my own code, but nothing appears to be working... I'm mostly getting incorrect results.

X and J are variables that have been entered by the user.

```for (int i = 1; i < j; i++)
sum += (pow(-1, i - 1)) / (5 * i - 1) * (pow(x, 5 * i - 1));
}```
Jun 20, 2022 in C++ 1,288 views

## 1 answer to this question.

It is part of a series.

Replace pow() with the previous iteration's value.

There is no need for code to call pow ().

Pow(x, 5 * I - 1) and pow(-1, I - 1) may be formed since both have an int exponent dependent on the iterator I from the previous loop iteration.

Example:
Let f(x, i) = pow(x, 5 * i - 1)
Then f(x, 1) = x*x*x*x
and f(x, i > 1) = f(x, i-1) * x*x*x*x*x

```double power_n1 = 1.0;
double power_x5 = x*x*x*x;
for (int i = 1; i < j + 1; i++)
// sum += (pow(-1, i - 1)) / (5 * i - 1) * (pow(x, 5 * i - 1));
sum += power_n1 / (5 * i - 1) * power_x5;
power_n1 = -power_n1;
power_x5 *= x*x*x*x*x;
}```
• 4,960 points

## How can I get the maximum or minimum value in a vector?

In C++, how can I find the greatest or minimum value in a vector? Is it correct to assume that it would be similar with an array? Do I require an iterator?  I tried max element, but I kept receiving errors. vector<int>::const_iterator it; it = max_element(cloud.begin(), cloud.end()); error: request for ...READ MORE

## how the iterator in c++ could be printed?

Suppose, I have declared a vector in C++ like ...READ MORE

## How can I get the size of a C++ function?

In C++, how can I find the size& ...READ MORE

## Use of min and max functions in C++

Are std::min and std::max better than fmin ...READ MORE

## Power Math in Python

When you use "^" operator, it is ...READ MORE

## What is the C++ function to raise a number to a power?

What's the best way to raise a n ...READ MORE

## lower_bound == upper_bound

Lower bound: the initial greater-or-equal element. Upper bound: ...READ MORE

## Why aren't cmath's pow and sqrt templates?

I'm curious as to why std::sqrt and ...READ MORE