fork(1) download
  1. #include <stdio.h>
  2. //正の奇数nを引数とし,以下の正の奇数の和を求める関数
  3. int rec(int n){
  4. if (n == 0){
  5. return 0;
  6. }
  7. else if(n==1){
  8. return 1;
  9. }
  10. else{
  11. return n+rec(n-2);
  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. else {
  20. printf("%d以下の正の偶数の和は%d\n",n,rec(n));
  21. }
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
11以下の正の奇数の和は36