Last active
January 2, 2023 07:55
-
-
Save marttp/74148b4fa97e6ac5c2ee94dff481bc00 to your computer and use it in GitHub Desktop.
Example of programming paradigm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Circle(val radius: Double) { | |
fun getArea(): Double { | |
return Math.PI * radius * radius | |
} | |
} | |
fun main(args: Array<String>) { | |
val c = Circle(5.0) | |
println("The area of the circle is ${c.getArea()}") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int factorial(int n) { | |
int result = 1; | |
for (int i = 1; i <= n; i++) { | |
result *= i; | |
} | |
return result; | |
} | |
int main() { | |
int n = 5; | |
printf("The factorial of %d is %d\n", n, factorial(n)); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun factorial(n: Int): Int { | |
return if (n == 0) 1 else n * factorial(n - 1) | |
} | |
println("The factorial of 5 is " + factorial(5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment