File tree 3 files changed +44
-4
lines changed
3 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -740,8 +740,8 @@ In order to achieve greater coverage and encourage more people to contribute to
740
740
</a>
741
741
</td>
742
742
<td> <!-- Swift -->
743
- <a href="./CONTRIBUTING.md ">
744
- <img align="center" height="25" src="./logos/github .svg" />
743
+ <a href="./src/swift/exponentiation.swift ">
744
+ <img align="center" height="25" src="./logos/swift .svg" />
745
745
</a>
746
746
</td>
747
747
<td> <!-- Rust -->
@@ -798,8 +798,8 @@ In order to achieve greater coverage and encourage more people to contribute to
798
798
</a>
799
799
</td>
800
800
<td> <!-- Swift -->
801
- <a href="./CONTRIBUTING.md ">
802
- <img align="center" height="25" src="./logos/github .svg" />
801
+ <a href="./src/swift/recursiveExponentiation.swift ">
802
+ <img align="center" height="25" src="./logos/swift .svg" />
803
803
</a>
804
804
</td>
805
805
<td> <!-- Rust -->
Original file line number Diff line number Diff line change
1
+ /* exponentiation.swift
2
+ Written by Roberto Martins on 10/10/2023
3
+ */
4
+
5
+ func exponentiation< Number: Numeric > ( base: Number , power: Int ) -> Number {
6
+ var result = base
7
+ if power == 0 {
8
+ return 1
9
+ }
10
+ for _ in 0 ..< power - 1 {
11
+ result *= base
12
+ }
13
+ return result
14
+ }
15
+
16
+ func main( ) {
17
+ print ( exponentiation ( base: 5 , power: 3 ) )
18
+ print ( exponentiation ( base: 2.5 , power: 4 ) )
19
+ print ( exponentiation ( base: 50 , power: 0 ) )
20
+ }
21
+
22
+ main ( )
Original file line number Diff line number Diff line change
1
+ /* recursiveExponentiation.swift
2
+ Written by Roberto Martins on 10/10/2023
3
+ */
4
+
5
+ func recursiveExponentiation< Number: Numeric > ( base: Number , power: Int ) -> Number {
6
+ if ( power == 0 ) {
7
+ return 1
8
+ }
9
+ return base * recursiveExponentiation( base: base, power: power - 1 )
10
+ }
11
+
12
+ func main( ) {
13
+ print ( recursiveExponentiation ( base: 5 , power: 3 ) )
14
+ print ( recursiveExponentiation ( base: 2.5 , power: 4 ) )
15
+ print ( recursiveExponentiation ( base: 50 , power: 0 ) )
16
+ }
17
+
18
+ main ( )
You can’t perform that action at this time.
0 commit comments