1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <stdio.h> int sum_iter(int n) { int i,sum=0; for(i=1;i<=n; i++) sum += i; return sum; } int sum_rc(int n) { if(n == 1) return 1; else return n+sum_rc(n-1); } int main(void) { int result; result = sum_iter(10); printf("sum_iter(10) = %d \n",result); result = sum_rc(10); printf("sum_rc(10) = %d \n",result); } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <stdio.h> char hello[20] = "Hello world!!!"; void print_char(char hello[], int n) { if(hello[n] != NULL) print_char(hello,n+1); else return; putchar(hello[n]); } int main(void) { print_char(hello,0); } | cs |