Here's mine
C
#include <stdio.h> unsigned long gcd(unsigned long a, unsigned long b) { while (a != 0) { unsigned long c = a; a = b % a; b = c; } return b; } unsigned long lcm(unsigned long a, unsigned long b) { return a * ( b / gcd(a, b) ); } int main () { unsigned int i = 2; unsigned long result = 1; for (i = 2; i < 20; i++) { result = lcm(result, i); } printf("%d\n", result); }
And Go
package main import ( "fmt" ) func gcd(a, b int64) int64 { for b != 0 { a, b = b, a%b } return b } func lcm(a, b int64) int64 { return a * (b / gcd(a, b)) } func main() { var result, i int64 = 1, 2 for ; i <= 20; i++ { result = lcm(result, i) } fmt.Println(result) }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's mine
C
And Go