I need an integer arithmatic program to compute a sequence of Fibonacci numbers.
ID: 3629082 • Letter: I
Question
I need an integer arithmatic program to compute a sequence of Fibonacci numbers. The total number in the sequence shoulud be defined from the command line input. For example, calling ./a.out 10 will output 10 numbers.also... I need to take a command line input and check if the number is within the Fibonacci sequence or not. If yes, the output confirmation is "[the number] is in the Fibonacci sequence and the index is [the index]", where [the number] is the number from the command line input and [the index] is the index of the nmber in the Fibonacci sequence.
What I have so far is:
#include <stdio.h>
#include <stdlib.h>
#define MAX_FIBONACCI_INDEX 100
int main (int argc, char **argv)
{
printf(" Fabonacci Number Sequence ");
int totalNUM;
int Fib[MAX_FIBONACCI_INDEX];
// get the total number
totalNum = atoi(argv[1]);
printf("totalNum = %d ", totalNum);
// calculate the sequence
Fib[0] = 0; Fib[1] = 1;
for(
..I need help from here...
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#define MAX_FIBONACCI_INDEX 100
int main (int argc, char **argv)
{
printf(" Fabonacci Number Sequence ");
int totalNUM;
int Fib[MAX_FIBONACCI_INDEX];
// get the total number
totalNum = atoi(argv[1]);
printf("totalNum = %d ", totalNum);
// calculate the sequence
Fib[0] = 0; Fib[1] = 1;
for(int i =2; i<totalNum; i++)
Fib(i) = Fib(i-1) + Fib(i-2) ;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.