fork download
  1. #include <stdio.h>
  2. int rec(int n){
  3. if (n == 1){
  4. return 1;
  5. }
  6. else{
  7. return n*n+rec(n-1);
  8. }
  9. }
  10. int main(void) {
  11. int n;
  12. for(n=1;n<=4;n++){
  13. printf("1から%dまでの二乗和の値は%d\n", n, rec(n));
  14. }
  15. return 0;
  16. }
  17.  
  18.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
1から1までの二乗和の値は1
1から2までの二乗和の値は5
1から3までの二乗和の値は14
1から4までの二乗和の値は30