Question:Fibonacci series using array in c 

Answer 
#include<stdio.h>
int main(){

    int i,range;
    long int arr[40];

    printf("Enter the number range: ");
    scanf("%d",&range);

    arr[0]=0;
    arr[1]=1;

    for(i=2;i<range;i++){
         arr[i] = arr[i-1] + arr[i-2];
    }

    printf("Fibonacci series is: ");
    for(i=0;i<range;i++)
         printf("%ld ",arr[i]);
  
    return 0;
}
Sample output: Enter the number range: 20 Fibonacci series is: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 

+ ExplanationNot Moderated
+ Report
Total Preview: 573
Fibonacci series using array in c
Copyright © 2024. Powered by Intellect Software Ltd