From fce50a9d7c6a6a35e6b06b9e77a4b43f0dec3085 Mon Sep 17 00:00:00 2001 From: Krishna Vedala Date: Sat, 7 Mar 2020 10:40:44 -0500 Subject: [PATCH] add commandline option to FibonacciDP.c --- misc/Fibonacci_DP.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/misc/Fibonacci_DP.c b/misc/Fibonacci_DP.c index de605f78..52d99db1 100644 --- a/misc/Fibonacci_DP.c +++ b/misc/Fibonacci_DP.c @@ -31,12 +31,17 @@ int fib(int n) return f[n]; } -int main(){ +int main(int argc, char *argv[]) +{ int number; //Asks for the number/position of term in Fibonnacci sequence - printf("Enter the value of n(n starts from 0 ): "); - scanf("%d", &number); + if (argc == 2) + number = atoi(argv[1]); + else { + printf("Enter the value of n(n starts from 0 ): "); + scanf("%d", &number); + } printf("The nth term is : %d \n", fib(number));