#include <stdio.h>
//再帰を用いて1からnまでの二乗和1^2 + 2^2 + 3^2 + ... + n^2を計算する
int rec(int n){
if (n == 1){
return 1;
}
else{
return rec(n-1)+n*n;
}
}
int main(void) {
int n = 4;
int i;
for(i=1;i<=n;i++){
rec(i);
printf("1から%dまでの二乗和の値は%d\n", i
, rec
(i
)); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Ci8v5YaN5biw44KS55So44GE44GmMeOBi+OCiW7jgb7jgafjga7kuozkuZflkowxXjIgKyAyXjIgKyAzXjIgKyAuLi4gKyBuXjLjgpLoqIjnrpfjgZnjgosKaW50IHJlYyhpbnQgbil7CiAgICBpZiAobiA9PSAxKXsKcmV0dXJuIDE7CiAgICB9CiAgICBlbHNlewpyZXR1cm4gcmVjKG4tMSkrbipuOwogICAgfQp9CmludCBtYWluKHZvaWQpIHsKICAgIGludCBuID0gNDsKICAgIGludCBpOwogICAgZm9yKGk9MTtpPD1uO2krKyl7CiAgICAJcmVjKGkpOwogICAgCXByaW50ZigiMeOBi+OCiSVk44G+44Gn44Gu5LqM5LmX5ZKM44Gu5YCk44GvJWRcbiIsIGksIHJlYyhpKSk7CiAgICB9CiAgICAKCXJldHVybiAwOwp9Cgo=