Docsity

C Program to Print Fibonacci Series, Exercises of Compiler Construction

Toggle sidebar
bg1
Example - Write a program to print Fibonacci series in c
#include<stdio.h>
int main(){
int k,r;
long int i=0l,j=1,f;
//Taking maximum numbers form user
printf("Enter the number range:");
scanf("%d",&r);
printf("FIBONACCI SERIES: ");
printf("%ld %ld",i,j); //printing firts two values.
for(k=2;k<r;k++){
f=i+j;
i=j;
j=f;
printf(" %ld",j);
}
return 0;
}
Sample output:
Enter the number range: 15
FIBONACCI SERIES: 0 1 1 2 3 5 8 13 21 34 55 89 144 233
377

Partial preview of the text

Download C Program to Print Fibonacci Series and more Exercises Compiler Construction in PDF only on Docsity!

Example - Write a program to print Fibonacci series in c

#include<stdio.h>

int main(){ int k,r; long int i=0l,j=1,f; //Taking maximum numbers form user printf("Enter the number range:"); scanf("%d",&r); printf("FIBONACCI SERIES: "); printf("%ld %ld",i,j); //printing firts two values. for (k=2;k<r;k++){ f=i+j; i=j; j=f; printf(" %ld",j); } return 0 ; }

Sample output:

Enter the number range: 15

FIBONACCI SERIES: 0 1 1 2 3 5 8 13 21 34 55 89 144 233