Write an ARM program to compute and store 9 Fibonacci number

Write an ARM program to compute and store 9 Fibonacci numbers to an array Fibonacci numbers are the numbers in the following integer sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 ... Condition: You have to use loop to traverse the array Use sp as your base address. In starting code, I already save that to r_0 You can initialize the first two numbers (0 and 1) manually (see starting code) You don\'t need to use any recursive method. If you don\'t know what recursion means, ignore this sentence.

Solution

//Fibonacci Series using Dynamic Programming

#include<stdio.h>

int fib(int n)

{

  /* Declare an array to store Fibonacci numbers. */

  int f[n+1];

  int i;

  /* 0th and 1st number of the series are 0 and 1*/

  f[0] = 0;

  f[1] = 1;

  for (i = 2; i <= n; i++)

  {

      /* Add the previous 2 numbers in the series

         and store it */

      f[i] = f[i-1] + f[i-2];

  }

  return f[n];

}

int main ()

{

  int n = 9;

  printf(\"%d\", fib(n));

  getchar();

  return 0;

}

 Write an ARM program to compute and store 9 Fibonacci numbers to an array Fibonacci numbers are the numbers in the following integer sequence: 0, 1, 1, 2, 3, 5

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site