Home / Programs / Nth Fibonacci Number using Command Line Arguments
🚀 Programming Example

Nth Fibonacci Number using Command Line Arguments

👁 585 Views
💻 Practical Program
📘 Step Learning
Nth Fibonacci Number using Command Line Arguments

💻 Program Code

#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;
    }
}
                        

🖥 Program Output

10

55
                            

📘 Explanation

Nope
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.