Programming Example
Write a Program Fibonacci Series Using Command Line Arguments
This is a program of Fibonacci Series using Command Line Arguments
#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;
}
10
These are 10 values in Fibonacci series are by atnyla:-
0
1
1
2
3
5
8
13
21
34
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.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.