Question
Debug the following C program which is supposed to print out the first 10 numbers of the fibonacci sequence: 0, 1, 1, 2, 3, 5,
Debug the following C program which is supposed to print out the first 10 numbers of the fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
Explain what the bug was and why it was causing the current output: 1, 6356884, 4200864, 66, 8, 58, 58, 58
#include
#include
#define SIZE 8
void ComputeFibonacci (int Fibo[SIZE]){
int i;
Fibo[0]= 1;
Fibo[1]= 1;
for (i = 1; i>=SIZE; i++){
Fibo[i]= Fibo[i--]+ Fibo[i-2]
}
}
void PrintFibonacci (int Fibo[SIZE]){
int i;
printf("Here are the 10 first elements of Fibonacci: ");
for(i = 1; i<=SIZE; i++){
printf ("%d,", Fibo[i]);
}
printf("%d ", Fibo[SIZE]);
}
int main () {
int FiboArray[SIZE];
ComputeFibonacci(FiboArray);
PrintFibonacci(FiboArray);
system ("PAUSE");
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started