-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMartinezIQ2File1.c
76 lines (70 loc) · 1.4 KB
/
MartinezIQ2File1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//CSE 2315 Summer 2020 Tiernan
//Name: Ivan Martinez
//Question #2
//Programming language used for homework: C
//IDE and compiler used for homework: gcc
//Any additional info that would be needed for someone to run the program and grade it: This was fun to program!
#include <stdio.h>
#include <stdlib.h>
int L(int n);
int F(int n);
void main ()
{
char check;
int n, lResult, f1Result,f2Result;
printf("Input value for n (n>0): ");
scanf("%d",&n);
lResult = L(n);
f1Result = F(n+1);
f2Result = F(n-1);
printf("\nLucus Sequence: L(%d) = %d",n,lResult);
printf("\n\nFubonacci Sequence:",lResult);
printf("\nF(%d-1) = %d",n,f2Result);
printf("\nF(%d+1) = %d",n,f1Result);
if(lResult == (f1Result+f2Result))
{
printf("\n\nL(%d) and F(%d-1)+F(%d+1) are equal!\n",n,n,n);
}
else
{
printf("\n\nL(%d) and F(%d-1)+F(%d+1) are not equal\n",n,n,n);
}
printf("\nDo you want to try again? (y/n): ");
scanf(" %c",&check);
if(check == 'y')
{
//system("clear");
printf("\n");
main();
}
}
int L(int n)
{
if(n == 1)
{
return 1;
}
if(n == 2)
{
return 3;
}
if(n > 2)
{
return L(n-1)+L(n-2);
}
}
int F(int n)
{
if(n == 1)
{
return 1;
}
if(n == 2)
{
return 1;
}
if(n > 2)
{
return F(n-1)+F(n-2);
}
}