Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

3. What are potential solutions?

Answered: 1 week ago