Answer to Question #285352 in Java | JSP | JSF for Hasty

Question #285352

Write a Program to display sum of the following series:

1-3+5-7+9.....n terms

Using following method prototype:

int  series(int n)


1
Expert's answer
2022-01-07T01:50:29-0500

int  series(int n) {

if (n % 2 == 0) return series(n - 1);

    if (n < 0) return 0;

    if (n == 1) return 1;

    else if ((n + 1) % 4 == 0) return series(n - 2) - n;

    else return series(n - 2) + n;

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog