TCS Command Line Arguments – Fibonacci Series

Ques. Write a Program Fibonacci Series Using Command Line Arguments for TCS

Please find below  the code for Fibonacci Series Using Command Line Arguments for TCS preparation made easy.

Note: Please go through Command Line Arguments Post before preparing for these questions. The theory there for TCS command line Program will help you in better understanding.

 #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 PrepInsta:-\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;
 
}