This C Program computes first N fibonacci numbers using command line arguments.
Here is source code of the C Program to compute first N fibonacci numbers using command line arguments. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Compute First N Fibonacci Numbers using Command Line Arguments
*/
#include <stdio.h>
/* Global Variable Declaration */
int first = 0;
int second = 1;
int third;
/* Function Prototype */
void rec_fibonacci(int);
void main(int argc, char *argv[])/* Command line Arguments*/
{
int number = atoi(argv[1]);
printf("%d\t%d", first, second); /* To print first and second number of fibonacci series */
rec_fibonacci(number);
printf("\n");
}
/* Code to print fibonacci series using recursive function */
void rec_fibonacci(int num)
{
if (num == 2) /* To exit the function as the first two numbers are already printed */
{
return;
}
third = first + second;
printf("\t%d", third);
first = second;
second = third;
num--;
rec_fibonacci(num);
}
$ cc arg6.c $ a.out 10 0 1 1 2 3 5 8 13 21 34
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
If you wish to look at programming examples on all topics, go to C Programming Examples.
Next Steps:
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Buy C Books
- Buy Computer Science Books
- Apply for Computer Science Internship
- Watch Advanced C Programming Videos
- Apply for C Internship