a. (100 points) Write a program to generate a table of values for the Fibonacci
ID: 3671173 • Letter: A
Question
a.(100 points) Write a program to generate a table of values for the Fibonacci sequence up to the largest value that can be stored without truncation or rounding using the long integer type in the Omega Unix gcc.
User interface:
Fibonacci sequence generator.
Output method:
a for list
b for table
Selection the output method :
Set up the interface similar to Lab 05 where the input is allowed to be either lower or upper case
If the user enters any value other than a or b, then terminate the program stating: “Invalid entry. Program Terminated.”
Start the Fibonacci sequence with 0.
Generate the values and save them in an array in the main function.
Create two functions to implement the output depending on the user selection1st function:
called: fib_list
return type: void
parameters:
list (the array of Fibonacci values)
n (number of values in array)
perLine (number of values to print per line)
purpose:
Outputs:
<new line>First <n> values of Fibonacci sequence are:<new line>
Outputs the perLine values per line with each separated by a comma
note: do not put a comma at the end of the last value
2nd function:
called: fib_table
return type void
parameters:
list (the array of Fibonacci values)
n (number of values in array)
purpose:
Outputs:
<new line>First <n> values of Fibonacci sequence are:<new line>
Index<tab>Fibonacci Value
<index (starting at 1)>< ><Fibonacci value><new line>
note: output table index 1 is actually array index 0
Fibonacci sequence generator.
Output method:
a for list
b for table
Selection the output method :
Explanation / Answer
/* Fibonacci Series c language */
#include<stdio.h>
int main()
{
int n, first = 0, second = 1, next, c;
printf("Enter the number of terms ");
scanf("%d",&n);
printf("First %d terms of Fibonacci series are :- ",n);
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
printf("%d ",next);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.