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