遞迴_Sum of Squares with Recursion

 avatar
user_3763047219
c_cpp
a year ago
238 B
1
Indexable
Never
#include <stdio.h>

int square(int num) {
	while (num >= 1) {
		if (num == 1) {
			return 1;
		}
		else {
			return num*num + square(num - 1);
		}
	}
}
int main() {
	int n = 0;
	scanf("%d", &n);
	printf("%d", square(n));
}