Qn: Write a simple C program to print "Fibonacci" series up to a given number.
-By Priscilla, Last Update On 28th May,2019 12:12 am
#include<stdio.h>
#include<conio.h>
int main(){
  int f1 = 0, f2 = 1, fibno_series, i, n;
  printf("\nEnter how many terms you want to print: ");
  scanf("%d",&n);
  printf("Fibonacci Series is up to %d terms:\n",n);
  printf("%d, %d, ",f1,f2);
  for(i = 3;i<= n;i++) {
    fibno_series = f1 + f2;
    printf("%d, ",fibno_series);
    f1 = f2;
    f2 = fibno_series;
  }
return 0;
}
Output:
Enter how many terms you want to print: 10
Fibonacci Series is up to 10 terms:
0,1,1,2,3,5,8,13,21,34

Pgcomments

Comments