Last active
January 12, 2019 23:48
-
-
Save valtyriel/51453209000c56674f4981825faf4bd0 to your computer and use it in GitHub Desktop.
This file contains 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
package main | |
import "fmt" | |
// Q1. Write a function that takes in a number and | |
// returns the next number that is divisible by 7. | |
func next7(n int) int { | |
n++ | |
if n%7 == 0 { | |
return n | |
} | |
return next7(n) | |
} | |
// Q2. Write a function that takes in two numbers | |
// and returns their greatest common divisor. | |
func gcd(a, b int) int { | |
if b == 0 { | |
return a | |
} | |
return gdc(b, a%b) | |
} | |
func main() { | |
fmt.Println("next multiple of seven after i:") | |
for i := 0; i < 20; i++ { | |
fmt.Printf("%v: %v\n", i, next7(i)) | |
} | |
fmt.Println() | |
fmt.Println("Greatest common divisor of a,b:") | |
for i := -10; i < 10; i++ { | |
for j := -10; j < 10; j++ { | |
fmt.Printf("%v, %v: %v\n", i, j, gcd(i, j)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment