Skip to content

Instantly share code, notes, and snippets.

@marttp
Last active January 2, 2023 07:55
Show Gist options
  • Save marttp/74148b4fa97e6ac5c2ee94dff481bc00 to your computer and use it in GitHub Desktop.
Save marttp/74148b4fa97e6ac5c2ee94dff481bc00 to your computer and use it in GitHub Desktop.
Example of programming paradigm
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()}")
}
#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;
}
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