61.2k views
8 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.

1 Answer

10 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 Nick Mazurkin
by
5.0k points