Fibonacci Sequence - C program
Tagged:
I edit my previous post in fibonacci number to display the sequence up to nth number. I still used array to implement this problem. Future post will be fibonacci sequence using recursive function.
#include<stdio.h>
int main(){
int arr[100];
arr[0] = 1;
arr[1] = 1;
int n;
int i;
printf("enter n: ");
scanf("%i", &n);
int x = 2;
while(x<n){
arr[x] = arr[x-1] + arr[x-2];
x++;
}
for(i=0; i<n; i++)
printf("%i ", arr[i]);
return 0;
}
output:
![]()

Post new comment