It's me again hehe.. well, i have to do 10 exercises in C++. I already did 9. I'm here because i can't understand the last one... i have the sigma function of the equation only, but i don't know how to do the other part (xi/i!). This is the excersice:
It is repeated twice , just down I translated it into English so that it is understood since I speak Spanish. So you know now that what i'm saying with the "xi/i!" part. Here is my code with the sigma (i=1 Σ n) part:
#include <iostream>
#include <conio.h>
#include <windows.h>
usingnamespace std;
//FUNCTION SIGMA
int sigma(int a, int b){
int sum = 0;
//THIS SUM I TO N
for (int i=0; i<=a; i++){
sum = sum+i;
}
return sum;
}
int x; //GLOBAL VARIABLES INT
int n;
int main(){
textcolor(11);
gotoxy(6,4); cprintf("I can solve sigma");
textcolor(15);
gotoxy(24,6); cprintf("Enter N: ");
cin >> x;
textcolor(15);
gotoxy(24,8); cprintf("Enter X: ");
cin >> n;
//PRINT THE RESULT
textcolor(15);
gotoxy(24,10); cprintf("Result is: "); cout << sigma (n, x);
getch();
return 0;
}
That's all, but i don't know what to do with X and the other part of the equation :( if anyone please can give me a solution for this!? Thank you for reading!!
Is the problem poorly stated? It says to "solve" the equation, but it doesn't say which variables are known and which are unknown. Are they all unknown? Is (R = 0, n = 1, x = 0) a solution?
The engineer who teaches us told us that R has to be found with Equation.
He gave us a little guide he made in a program but i did not understand it , I'll show you:
OK, so it's not really "solve" then, but "implement".
Your summation is not implemented correctly. You need to compute x / 1 + x^2 / 2 + x^3 / 6 + x^4 / 24 + ... + x^n / n!. You're only computing 0 + 1 + 2 + 3 + ... + n
I know, but thats why i'm asking for the solution, i don't know too much of C++ thats why i'm studying, so, if you can write the code for me, i will thank you helios!
If I can give you an hint , look for recursive function in Google.
The method should not take more than 10 lines of code for sure.
This is not an iterative method. It is a fast method call technique but that will increase the call stack frame size so make sure to start with 10 or something not 4000 !
Reply with a recursive function and then we can help you with arithmetics.