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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!