P055.c (838B)
1 /* WAP to print n terms of Fibbonacci Series (Starting from term 0) */ 2 3 // This code has not been compiled. 4 // If you find any issues, please create a new issue on GitHub regarding them. 5 // Go to this link to create a new issue: https://github.com/notamitgamer/bsc/issues 6 7 #include <stdio.h> 8 9 void printFibonacci(int); 10 11 void printFibonacci(int n) 12 { 13 int val1 = 0, val2 = 1, val3, i; 14 printf("\nFibonacci series upto %d terms :", n); 15 if (n < 0) 16 printf(" N/A"); 17 if (n == 0) 18 printf(" %d", val1); 19 if (n > 0) 20 printf(" %d %d", val1, val2); 21 for (i = 2; i <= n; i++) 22 { 23 val3 = val1 + val2; 24 printf(" %d", val3); 25 val1 = val2; 26 val2 = val3; 27 } 28 } 29 30 int main() 31 { 32 int n; 33 printf("Enter the n : "); 34 scanf("%d", &n); 35 printFibonacci(n); 36 return 0; 37 }