Home / Programs / Write a Program Fibonacci Series Using Command Line Arguments
Programming Example

Write a Program Fibonacci Series Using Command Line Arguments

👁 2,610 Views
💻 Practical Program
📘 Step by Step Learning
This is a program of Fibonacci Series using Command Line Arguments

Program Code

#include<stdio.h>
#include<stdlib.h>

int main (int argc, char *argv[]) 
{

    int n, first = 0, second = 1, next, c;
  
    n = atoi (argv[1]);
  
 
    printf ("These are %d values in Fibonacci series are by atnyla:-\n",n);
  
    for (c = 0; c < n; c++)
    {
        if (c <= 1)
	      next = c;
        else
		{
	        next = first + second;
	        first = second;
	        second = next;
        }
    
    printf ("%d\n", next);
    
        
    }
  
  return 0;
}

Output

10

These are 10 values in Fibonacci series are by atnyla:-
0
1
1
2
3
5
8
13
21
34


Explanation

Nope

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.