fork download
  1. #include <stdio.h>
  2. //練習問題E
  3. #include <stdio.h>
  4. //練習問題E
  5.  
  6. int tri(int n) {
  7. if (n == 0) {
  8. return 0;
  9. } else if (n == 1) {
  10. return 0;
  11. } else if (n == 2) {
  12. return 1;
  13. } else {
  14. return tri(n - 1) + tri(n - 2) + tri(n - 3);
  15. }
  16. }
  17.  
  18. int main(void) {
  19. int n = 7;
  20. printf("数列Tnについて, n=%dのときの値は%d\n", n, tri(n));
  21. return 0;
  22. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
数列Tnについて, n=7のときの値は13