added weekly exercises of isp-ws25
This commit is contained in:
36
c/isp-ws25/weeklies/week03/w03ex03.c
Executable file
36
c/isp-ws25/weeklies/week03/w03ex03.c
Executable file
@@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int lucas(int number);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int index_position = 0;
|
||||
int lucas_number = 0;
|
||||
|
||||
printf("Enter index position: ");
|
||||
scanf("%d", &index_position);
|
||||
|
||||
if(index_position < 0)
|
||||
{
|
||||
printf("Entered position must be a non-negative integer\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
lucas_number = lucas(index_position);
|
||||
|
||||
printf("lucas(%d) = %d\n", index_position, lucas_number);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lucas(int number)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if(number == 0){return 2;}
|
||||
if(number == 1){return 1;}
|
||||
|
||||
result = lucas(number - 1) + lucas(number - 2);
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user