File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 51
51
52
52
53
53
$ n = 10 ;
54
+ $ x = 110 ;
54
55
55
56
echo "The factor of {$ n } is : " .factorial ($ n ) . PHP_EOL ;
56
57
58
+ echo "The Fibonacci number of {$ n } is : " . fibonnacci ($ n ) . PHP_EOL ;
59
+
60
+ echo "The Greatest Common Division of {$ n } and {$ x } is : " . gcd ($ n , $ x ) . PHP_EOL ;
61
+
57
62
echo "Be sure to check the docblock of this file for more explanation! " . PHP_EOL ;
58
63
64
+
59
65
function factorial (int $ n ) : int
60
66
{
61
67
@@ -68,3 +74,23 @@ function factorial(int $n) : int
68
74
return $ n * factorial ($ n - 1 );
69
75
}
70
76
77
+ function fibonnacci (int $ n ) : int
78
+ {
79
+ if ($ n == 0 ){
80
+ return 1 ;
81
+ } else if ($ n == 1 ) {
82
+ return 1 ;
83
+ } else {
84
+ return fibonnacci ($ n - 1 ) + fibonnacci ($ n - 2 );
85
+ }
86
+ }
87
+
88
+ function gcd (int $ a , int $ b ) : int
89
+ {
90
+ if ($ b == 0 ) {
91
+ return $ a ;
92
+ } else {
93
+ return gcd ($ b , $ a % $ b );
94
+ }
95
+ }
96
+
You can’t perform that action at this time.
0 commit comments