I have been asked to do this:
Please input Number: 4
+-+-+-+
+
+
+-+
+
Total is 5
Other Examples”
Please input Number: 5
+-+-+-+-+
+
+
+-+
+
+
+-+-+
+
+
total is 8
While this problem is driving me insane. I have been coding and researching how fibonacci works while figuring out the pattern.
The best code that I ever come up is this:
#include <stdio.h>
#include <conio.h>
int fibo(int condition)
{
if(condition <= 2)
{
return printf("+");
}
else
{
printf("+");
printf("-");
printf("\n");
fibo(condition - 2) + fibo(condition - 1);
}
}
int main()
{
int takeNumber;
printf("Please give a number!\n");
scanf("%d",&takeNumber);
fibo(takeNumber);
getch();
}
He was very strict on the “only recursion rule”
I am confused and frustrated, I dont know if I should have seperated the ” + “, ” – ” and the “prinf(“\n”); “. I have tried it and got the stack overflow error.
It has been hard to study the pattern, can somebody help me out?
like this ?