// We have a number of bunnies and each bunny has two big floppy ears.
// We want to compute the total number of ears across all the bunnies
// recursively (without loops or multiplication).
//bunnyEars(0) → 0
//bunnyEars(1) → 2
//bunnyEars(2) → 4
#include <stdio.h>
// To enable debug messages uncomment #define
#define TEST 1
int bunnyEars(int bunnies);
void startTesting();
int main(void) {
#ifdef TEST
startTesting();
#endif
return 0;
}
int bunnyEars(int bunnies) {
if (bunnies == 0) {
return 0;
}
if (bunnies == 1) {
return 2;
}
return 2 + bunnyEars(bunnies - 1);
}
void startTesting()
{
int result = 0;
int i = 0;
for (i = 0; i <= 5; i++) {
result = bunnyEars(i);
printf("BunnyEars(%d) = %d\n", i
, result
); }
}