week_3_s_2
unknown
c_cpp
3 years ago
711 B
3
Indexable
#include <stdio.h> int foo(int n, int c); int foo1(int n, int c); int foo2(int n, int c); int main(int argc, char const *argv[]) { foo(128,0); printf("\n------------------\n"); foo1(128,0); printf("\n------------------\n"); foo2(128,0); printf("\n"); return 0; } int foo(int n, int c) { printf("Foo: %d ",c); c++; if(n == 1){ return 1; } else{ return 1 + foo(n / 2, c); } } int foo1(int n, int c) { printf("Foo1: %d ",c); c++; if(n == 1){ return 1; } else{ return 1 + 2*foo1(n / 2, c); } } int foo2(int n, int c) { printf("Foo2: %d ",c); c++; if(n == 1){ return 1; } else{ return 1 + foo2(n / 2, c) + foo2(n / 2, c); } }
Editor is loading...