Series Return values
Mar 8, 2012 at 5:08am UTC
I am trying to return the values for the terms of an arithmetic series. However, I am having difficulties in establishing the orientation of each "terms'" sign (+ or -). Any ideas? Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
for (i = firstTerm; abs (i) <= abs (maxValue); i = i + (d))
{
sum = sum + i;
if ((i) >= 0)
{
if (i != abs (maxValue))
{
cout << setw(2);
if (i < 0)
{
cout << i << " - " ;
}
else if (i > 0)
{
cout << i << " + " ;
}
}
else if (i = maxValue)
{
cout << i << " = " << sum;
}
}
else if ((i) <= 0)
{
if (i != maxValue)
{
cout << setw(2);
if (i < 0)
{
cout << " - " << abs (i);
}
else if (i > 0)
{
cout << " + " << abs (i);
}
}
else if (i = maxValue)
{
cout << " - " << abs (i) << " = " << sum;
}
}
Mar 8, 2012 at 10:53pm UTC
Hi
which arithmetic series is it ? and what kind of difficulties "in establishing the orientation " ?
Could you be more specific!
Topic archived. No new replies allowed.