/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include<stdio.h>
int main(void)
{
int i , x , n1 , n2 , fib;
printf("\nCALCOLO SEQUENZA DI FIBONACCI\n\n");
printf("\n\nQuanti numeri vuoi stampare massimo? ");
scanf("%d",&x);
if (x<=0) printf("\n ERRORE");
else if (x==1) printf("\n\nECCO LA SEQUENZA RICHIESTA: 1 ");
else if (x==2) printf("\n\nECCO LA SEQUENZA RICHIESTA: 1 , 1 ");
else {
n1=1;
n2=1;
printf("\n\nECCO LA SEQUENZA RICHIESTA: 1 , 1 ");
for (i=3 ; i<=x ; i++) {
fib=n1+n2;
printf(", %d ", fib);
n1=n2;
n2=fib;
}
}
printf("\n\n");
return 0;
}