Fibonacci Sequence - C program

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:

fibonacci sequence

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.