bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

pc-ip-13.c (1223B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 05 Jan 2026
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /*
      9  * Question 13:
     10  * Write a program to display the Fibonacci series using recursive function and iterative function.
     11  */
     12 
     13 #include <stdio.h>
     14 
     15 long long int fib_rec(int);
     16 void fib_rec_print(int);
     17 void fib_ite_print(int);
     18 
     19 int main()
     20 {
     21     int n;
     22     printf("Enter the number of terms: ");
     23     scanf("%d", &n);
     24     fib_rec_print(n);
     25     fib_ite_print(n);
     26     return 0;
     27 }
     28 
     29 void fib_rec_print(int n)
     30 {
     31     int i;
     32     printf("\nFibonacci Series (Recursion):");
     33     for (i = 0; i <= n; i++)
     34     {
     35         printf("  %lld", fib_rec(i));
     36     }
     37 }
     38 
     39 void fib_ite_print(int n)
     40 {
     41     int i, t1 = 0, t2 = 1, t3;
     42     printf("\nFibonacci Series (iteration):");
     43     if (n > 0)
     44     {
     45         printf("  0");
     46     }
     47     if (n > 1)
     48     {
     49         printf("  1");
     50     }
     51     for (i = 2; i <= n; i++)
     52     {
     53         t3 = t1 + t2;
     54         printf("  %d", t3);
     55         t1 = t2;
     56         t2 = t3;
     57     }
     58 }
     59 
     60 long long int fib_rec(int n)
     61 {
     62     if (n == 0 || n == 1)
     63     {
     64         return n;
     65     }
     66     else
     67     {
     68         return fib_rec(n - 1) + fib_rec(n - 2);
     69     }
     70 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror