0
I need to resolve this question: Make a program that reads the number of terms and a positive value for X. Calculate and show the value of the following series: * S = (-X2/! 1) (+X3/2! ) (-X4/3! ) (+X5/4! ) (-X6/3! ) (+X7/2! ) (-X8/1! ) (+X9/2! ) (-X10/3! ) (+X11/4!) -...
I have no idea how to make the factor increase and decrease in this way. I started making this code:
for (int i = 1; i < termos; i++) {
if (expoente % 2 == 0) { //se o expoente for par, x é negativo...
x = -x;
}
fatorial = calcFat(numFat); //calcula o fatorial do numero...
expoente++;
}
So I calculate item by item, but what’s left is just to do the cicular numFat from 1 to 4 and after 4 to 1.
ps: Function created to calculate factorial:
int calcFat(int num) { //calcula o fatorial e retorna seu valor...
int resultado = num;
for (int i = (num-1); i > 1; i--) {
resultado = resultado * i;
}
return resultado;
}
Thanks for the help!
One possibility is to define a counter variable and an increment with initial value. Each cycle adds the increment to the counter and if the counter is 1 or 4 you reverse the increment signal (increment = - increment;) the same way you did with variable x.
– anonimo
Thanks for the tip!
– Ruan
I edited the code of the question by putting some spaces...leave everything stuck, no spaces, it is even more difficult to understand...
– zentrunix