func recursion() {
recursion() /* function calls itself */
}
func main() {
recursion()
}
package main
import "fmt"
func factorial(i int) {
if(i = 1) {
return 1
}
return i * factorial(i - 1)
}
func main {
var i int = 15
fmt.Printf("Factorial of %d is %d\n", i, factorial(i))
}
package main
import "fmt"
func fibonaci(i int) {
if(i == 0) {
return 0
}
if(i == 1) {
return 1
}
return fibonaci(i-1) + fibonaci(i-2)
}
func main() {
var i int
for i = 0; i 10; i++ {
fmt.Printf("%d\t%n", fibonaci(i))
}
}
package main
import (
"fmt"
"os"
"strings"
"unicode/utf8"
)
func doPalindrome(s string) bool {
if utf8.RuneCountInString(s) = 1 {
return true
}
word := strings.Trim(s, "\t \r\n\v")
first, sizeOfFirst := utf8.DecodeRuneInString(word)
last, sizeOfLast := utf8.DecodeLastRuneInString(word)
if first != last {
return false
}
return doPalindrome(word[sizeOfFirst : len(word)-sizeOfLast])
}
func IsPalindrome(word string) bool {
s := ""
s = strings.Trim(word, "\t \r\n\v")
if len(s) == 0 || len(s) == 1 {
return false
}
return doPalindrome(s)
}
func main() {
args := os.Args[1:]
for _, v := range args {
ok := IsPalindrome(v)
if ok {
fmt.Printf("%s\n", v)
}
}
}