Last active
July 28, 2017 15:03
-
-
Save nolram/932996e8547009b4f37ff5c9b83e10bc to your computer and use it in GitHub Desktop.
Apenas algoritmos simples com propósito de aprendizado da linguagem Go
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" | |
) | |
const a int = 1 | |
type student struct { | |
nome string | |
sobrenome string | |
matricula string | |
idade int | |
} | |
func main() { | |
var b = 2 | |
fmt.Println("Constante", a) | |
fmt.Println("Variável", b) | |
fmt.Println("Loop") | |
for i:=1; i <= 5; i++ { | |
fmt.Println(i) | |
} | |
imprimeAlunos() | |
fmt.Println("\nImprime somente pares") | |
for j := 1; j <= 30; j++ { | |
if j % 2 == 0{ | |
fmt.Println(j) | |
} | |
} | |
fmt.Println("\nImprime Soma") | |
for x := 0; x <= 10; x++{ | |
fmt.Println(soma(x, x)) | |
} | |
} | |
func soma(x int, y int) int{ | |
return x + y | |
} | |
func imprimeAlunos() { | |
aluno1 := student{nome: "Marlon", sobrenome: "Baptista de Quadros", matricula: "12324565441", idade: 26} | |
aluno2 := student{nome: "Fulano", sobrenome: "Da Silva Sauro", matricula: "123456465416", idade: 20} | |
aluno3 := student{nome: "Ciclano", sobrenome: "De Souza", matricula: "13456478899", idade: 19} | |
alunos := make([]student, 3) | |
alunos[0] = aluno1 | |
alunos[1] = aluno2 | |
alunos[2] = aluno3 | |
aluno4 := student{nome: "Giclano", sobrenome: "De Moraes", matricula: "34555479741", idade: 18} | |
alunos = append(alunos, aluno4) | |
fmt.Println("\n" + aluno1.nome) | |
fmt.Println(aluno1.sobrenome) | |
fmt.Println(aluno1.nome , aluno1.sobrenome + "\n") | |
aluno1.nome = "Matheus" | |
fmt.Println(aluno1.nome + "\n") | |
fmt.Println("Loop por indice") | |
for k := 0; k < len(alunos); k++{ | |
fmt.Println(alunos[k]) | |
} | |
fmt.Println("\nForeach") | |
for _, k := range alunos { | |
fmt.Println(k) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment