Nth Fibonacci Number using Command Line Arguments

Using Command Line Arguments

[code language=”cpp”]
#include<stdio.h>
#include<stdlib.h>
int fib(int n)
{
int a=0,b=1,c,i;
if(n==0) return a;
for(i=2;i<=n;i++)
{
c=a+b;
a=b;
b=c;
}
return b;
}
int main(int argc, char * argv[])
{
if(argc==1)
{
printf(“No arguments”);
return 0;
}
else
{
int n;
n=atoi(argv[1]);
printf(“%d”,fib(n));
return 0;
}
}
[/code]

Get over 200+ Courses under One Subscription

mute

Don’t settle Learn from the Best with PrepInsta Prime Subscription

Learn from Top 1%

One Subscription, For Everything

The new cool way of learning and upskilling -

Limitless Learning

One Subscription access everything

Job Assistance

Get Access to PrepInsta Prime

Top Faculty

from FAANG/IITs/TOP MNC's

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.

Comments