Users Online
· Guests Online: 153
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
39 C Program to Compute First N Fibonacci Numbers using Command Line Arguments
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
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
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.