Well, we have three variables in that context: y is the value to be discovered, i is likely to be an informed value for the calculation and n would be the amount of times the calculation should be done.
Analyzing the problem:
y = i - i^2 + i^3 -i^4 +i^5 - ... +- i^n
I could notice a pattern. Initially we have the value of i, and then a subtraction by the sum of i elevated to the successor of every power (i^2) + (i^3) and soon after this double is subtracted by the sum of another double following the same pattern: ((i^2) + (i^3)) - ((i^4) + (i^5)).
In case I have intended correctly, the following code in C# theoretically would solve the problem:
Console.WriteLine("Informe o valor de i: ");
double i = double.Parse(Console.ReadLine());
Console.WriteLine("Informe o valor de n: ");
int n = int.Parse(Console.ReadLine());
double y = i;
for(int x = 2; x <= n; x++)
{
y = y - (Math.Pow(i,x) + Math.Pow(i,(x+1)));
x++;
}
Console.WriteLine("O valor de y = " + y);
I did the following Fiddle where you can do tests...
As a task, just try to run in C++.
In case I didn’t understand it right, please just comment first
of -1.
Please, who is negative, comment something.
– Daniel
Explain a little better... the function should receive a parameter
nand he must be the limit and anotheri? and then returny?– h3nr1ke
I think the reason you’re being negative is because it’s a challenge that’s been proposed to you, it’s the same as someone doing your homework. But now the important thing, should explain better the value of
iandn– krystalgamer
I believe that’s right @krystalgamer, he is "cheating" on a test, but we can help even without giving the answer... but as you mentioned... we need more information...
– h3nr1ke
I think that
...andi^ntogether means that for anyithe expression returns a value - but in my mathematical ignorance this is seeming to pile burst... ;)– Daniel