fork(1) download
  1. #include <stdio.h>
  2. //正の奇数nを引数とし,以下の正の奇数の和を求める関数
  3. int rec(int n){
  4. if (n == 1){
  5. return 1;
  6. }
  7. else if(0==n/2){
  8. return n-1;
  9. }
  10. else if(0!=n/2){
  11. return n+rec(n-2);
  12.  
  13. }
  14. }
  15. int main(void) {
  16. int n = 12;
  17. printf("%d以下の正の奇数の和は%d\n", n, rec(n));
  18. return 0;
  19. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
12以下の正の奇数の和は41