487,879 views
45 votes
45 votes
. Find the sum of the squares of the integers from 1 to MySquare, where

MySquare is input by the user. Be sure to check that the user enters a positive
integer.

User Adt
by
2.6k points

1 Answer

16 votes
16 votes

Answer:

in c

Step-by-step explanation:

#include <stdio.h>

int sumSquares(int n) {

if(n == 0) return 0; else if (n == 1) return 1; else return (n*n) + sumSquares(n - 1);

}

int main() {

int mySquare;

puts("Enter mySquare : ");

scanf("%d", &mySquare);

if(mySquare < 0) mySquare *= -1;// makes mySquare positive if it was negative

printf("Sum of squares: %d", sumSquares(mySquare));

}

User Sam Baumgarten
by
3.1k points