add commandline option to FibonacciDP.c

This commit is contained in:
Krishna Vedala 2020-03-07 10:40:44 -05:00
parent 90e6ee0771
commit fce50a9d7c
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7
1 changed files with 8 additions and 3 deletions

View File

@ -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));