int f( int x, int n )
{
int result=0;//Initialize the number which will hold the sum
for ( int k=1; k<=n; k++ )// ∑
result += x*x / k; // add x2/k to the sum
return result;//return the result
}
Note how Bazzy's example mirrors the form of f(x). It is much more clear and concise. Although, you may want result and the return value to be a double.
What can I do to start this a program in "Dev-C++ 4.9.9.2"May be I must write somethink.
1 2 3 4 5 6 7
int f( int x, int n )
{
int result=0;//Initialize the number which will hold the sum
for ( int k=1; k<=n; k++ )// ∑
result += x*x / k; // add x2/k to the sum
return result;//return the result
}
Functions in C++ work exactly as functions in mathematics. f of x, takes one parameter x and returns a single value (the y value) for the given x. Learning about functions in C++ might help you build a better understanding of Calculus. That's pretty cool, right?
That won't do to work.Excuse but can you write exactly please, from biggining to end.White copy and paste to work.I'm sory for my ignorance
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
int f( int x, int n )
{
int result=0;//Initialize the number which will hold the sum
for ( int k=1; k<=n; k++ )// ?
result += x*x / k; // add x2/k to the sum
return result;//return the result
//...
}
int main()
{
std::cout << "sum = "<< f ( /*a value for x*/, /*a value for n*/ ); // Here write out mistake
return 0;
}
This is getting a little bit ridiculous. Compile that source and it will tell you what is wrong. If you still have problems, post the compiler error and source again. Your problem is so trivial, it's hard to believe that you're putting any effort into this. Just give it a try; we have confidence in you.
My Discrete Math course had us evaluate a bunch of derivatives and integrals using different approximation techniques. It would have been awesome if our assignments were in C++ but, because there was no C++ prerequisite (some of the students were Math Ed.), we used Excel. We had to use a few cells for our values and copy them down about a thousand lines until the answers stabilized to x decimal places...it was lame--well, I guess it was alright; but it was no C++!
Thank you man.I hope be right.Because I nothing understand of C++ , and I just cope and paste your formula and it just not start, but I'm sure with a little more luck I well go to the end. I'm from Bulgaria and I,m a student in university