@anonymous/

SelfreliantLinenXenarthra

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.5334313068085779","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluDQoNCmltcG9ydCAiZm10Ig0KDQpmdW5jIG1haW4oKSB7DQoNCgl2YXIgbiBpbnQNCgl2YXIgbnVtIGludA0KCXZhciByZXN1bHQgaW50DQoNCglmbXQuUHJpbnRsbigiSG93IG1hbnkgaW50ZWdlcnMgR0NEIGRvIHlvdSB3YW50IHRvIGNhbGN1bGF0ZT8iKQ0KCWZtdC5TY2FuZigiJWRcbiIsICZuKQ0KCWZtdC5QcmludGxuKCJFbnRlciBzcGFjZSBzZXBhcmF0ZWQgaW50ZWdlcnM6IikNCgludW1MaXN0IDo9IG1hcFtpbnRdaW50e30NCg0KCWZvciBpIDo9IDE7IGkgPD0gbjsgaSsrIHsNCgkJZm10LlNjYW5mKCIlZCIsICZudW0pDQoJCW51bUxpc3RbaV0gPSBudW0NCgl9DQoJLy9UaGlzIGlzIHRoZSByZXN1bHQgZm9yIG9ubHkgMiBpbnRlZ2Vycw0KCXJlc3VsdCA9IGdjZChudW1MaXN0WzFdLCBudW1MaXN0WzJdKQ0KDQoJLy9mb3IgbG9vcCBpbiBjYXNlIHRoZXJlJ3JlIG1vcmUgdGhhbiAyIGludHMNCglmb3IgaiA6PSAzOyBqIDw9IG47IGorKyB7DQoJCXJlc3VsdCA9IGdjZChyZXN1bHQsIG51bUxpc3Rbal0pDQoJfQ0KDQoJZm10LlByaW50bG4oIlRoZSBHQ0QvSENGIG9mIGdpdmVuIGludGVnZXJzIGlzOiAiLCByZXN1bHQpDQp9DQoNCi8vRnVuYyB0byBpbXBsZW1lbnQgRXVjbGlkIEFsZ28NCmZ1bmMgZ2NkKHgsIHkgaW50KSBpbnQgew0KCWZvciB5ICE9IDAgew0KCQl4LCB5ID0geSwgeCV5DQoJfQ0KCXJldHVybiB4DQp9DQo="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main

import "fmt"

func main() {

	var n int
	var num int
	var result int

	fmt.Println("How many integers GCD do you want to calculate?")
	fmt.Scanf("%d\n", &n)
	fmt.Println("Enter space separated integers:")
	numList := map[int]int{}

	for i := 1; i <= n; i++ {
		fmt.Scanf("%d", &num)
		numList[i] = num
	}
	//This is the result for only 2 integers
	result = gcd(numList[1], numList[2])

	//for loop in case there're more than 2 ints
	for j := 3; j <= n; j++ {
		result = gcd(result, numList[j])
	}

	fmt.Println("The GCD/HCF of given integers is: ", result)
}

//Func to implement Euclid Algo
func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}