fork download
  1. #include <stdio.h>
  2.  
  3. int rec(int n){
  4. if (n==1){
  5. return 1;
  6. }
  7. else if(n==0){
  8. return 0;
  9. }
  10. else{
  11. return rec(n-2)+n;
  12. }
  13. }
  14. int main(void) {
  15. int n = 11;
  16. if(n%2==1){
  17. printf("%d以下の正の奇数の和は%d\n", n, rec(n));
  18.  
  19. }
  20. else if(n%2==0){
  21. printf("%d以下の正の偶数の和は%d\n",n,rec(n));
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
11以下の正の奇数の和は36