C Program to Print Fibonacci Series, Exercises of Compiler Construction

A simple c program to generate and print the fibonacci series up to a given number. The user is prompted to enter the range, and the program prints the first two values (0 and 1) followed by the rest of the series, calculated by adding the previous two numbers.

Typology: Exercises

2018/2019

Uploaded on 02/26/2019

human-not-robot
human-not-robot 🇮🇳

2 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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