Section7
This commit is contained in:
91
Section7/69.go
Normal file
91
Section7/69.go
Normal file
@@ -0,0 +1,91 @@
|
||||
// Coding Exercise #1
|
||||
// Using a for loop and an if statement print out all the numbers
|
||||
// between 1 and 50 that divisible by 7.
|
||||
|
||||
//package main
|
||||
//
|
||||
//import "fmt"
|
||||
//
|
||||
//func main() {
|
||||
// for i := 0; i < 51; i++ {
|
||||
// if i%7 == 0 {
|
||||
// fmt.Printf("%d ", i)
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// fmt.Println(" ")
|
||||
//}
|
||||
|
||||
// Coding Exercise #2
|
||||
// Change the code from the previous exercise and use the continue statement
|
||||
// to print out all the numbers divisible by 7 between 1 and 50.
|
||||
|
||||
//package main
|
||||
//
|
||||
//import "fmt"
|
||||
//
|
||||
//func main() {
|
||||
// for i := 0; i < 51; i++ {
|
||||
// if i%7 != 0 {
|
||||
// continue
|
||||
// }
|
||||
// fmt.Printf("%d ", i)
|
||||
// }
|
||||
// fmt.Println("")
|
||||
//}
|
||||
|
||||
// Coding Exercise #3
|
||||
// Change the code from the previous exercise and use the break statement
|
||||
// to print out only the first 3 numbers divisible by 7 between 1 and 50.
|
||||
|
||||
// package main
|
||||
//
|
||||
//import "fmt"
|
||||
//
|
||||
//func main() {
|
||||
// count := 0
|
||||
// for i := 0; i < 51; i++ {
|
||||
// if i%7 != 0 {
|
||||
// continue
|
||||
// }
|
||||
// fmt.Printf("%d ", i)
|
||||
// count++
|
||||
//
|
||||
// if count == 3 {
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// fmt.Println("")
|
||||
//}
|
||||
|
||||
// Coding Exercise #4
|
||||
// Using a for loop, an if statement and the logical and operator
|
||||
// print out all the numbers between 1 and 500 that divisible both by 7 and 5.
|
||||
|
||||
// package main
|
||||
//
|
||||
//import "fmt"
|
||||
//
|
||||
//func main() {
|
||||
// for i := 0; i <= 500; i++ {
|
||||
// if i%7 == 0 && i%5 == 0 {
|
||||
// fmt.Printf("%d ", i)
|
||||
// }
|
||||
// }
|
||||
// fmt.Println("")
|
||||
//}
|
||||
|
||||
// Coding Exercise #5
|
||||
// Using a for loop print out all the years from your birthday to the current year.
|
||||
// Use a variant of for loop where the post statement is moved inside the for block of code.
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
for i := 1978; i <= 2023; i++ {
|
||||
fmt.Printf("%d ", i)
|
||||
}
|
||||
fmt.Println("")
|
||||
}
|
||||
Reference in New Issue
Block a user