Free help with homework

Why join Brainly?

  • ask questions about your assignment
  • get answers with explanations
  • find similar questions


You can use the arithmetic formula for 1^2+2^2+3^2+...+n^2 = (n(n+1)(2n+1))/6

You can refer the same program what madakapoor10 was posted but the logic would be different.

Instead for loop you can assign an integer variable and substitute the formula.
Ex: int s = (n(n+1)(2n+1))/6 where n is the input value.

Here you can reduce the looping process and save time
1 4 1
The Brain
  • The Brain
  • Helper
Not sure about the answer?
Learn more with Brainly!
Having trouble with your homework?
Get free help!
  • 80% of questions are answered in under 10 minutes
  • Answers come with explanations, so that you can learn
  • Answer quality is ensured by our experts