No I'm ok, I have seen that function before, just needed refreshing. 'sum += i;' just means increment 'sum' by 'i' on each iteration right?
Quote
float Sigma(int n)
{
int i;
float sum = 0;
for (i = 0; i <= n; i++) sum += someFunction(i);
return sum;
}
Can you explain what is 'float Sigma(int n) {}'? Are you declaring a float type vairable, 'Sigma'? But then what is (int n)? Declaring an integer, 'n'? But then why is it in brackets following 'Sigma'? Is it because sigma is some function of n,? wWhat function? Also what about the curly parenthesis? Isn't that used to denote the arguments of a function in c, so how can this be a function, when all you are doing is declaring a variable? As you can see I have some problems with that first line, can you please clear it up for me?
next, what about the 'for( ; ; )' where are the statements and containing parenthesis for it? should it be:
float Sigma(int n)
{
int i;
float sum = 0;
for (i = 0; i <= n; i++)
{
sum += someFunction(i);
return sum;
}
}
As far as the rest goes, I understand you have declared an integer 'i' which is equivalent to my 'm' and a float, which is initialised as 0. You are evaluating the function at i on each loop, and incrementing the variable 'sum' by this value. So basically, for each loop you have f(i+1) + f(i), which is saved to the variable 'sum'?
It would be helpful if you could explain these things for me.
Edited by {Nabla}, 18 October 2008 - 01:46 PM.