prime number
This commit is contained in:
parent
1c7249f618
commit
55446a72e7
2 changed files with 26 additions and 1 deletions
25
loops/workshop2.go
Normal file
25
loops/workshop2.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package loops
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func Demo4() {
|
||||
number := 0
|
||||
fmt.Println("enter a number")
|
||||
fmt.Scanln(&number)
|
||||
|
||||
is_prime := true
|
||||
|
||||
for i := 2; i < number; i++ {
|
||||
if number%i == 0 {
|
||||
is_prime = false
|
||||
}
|
||||
}
|
||||
if is_prime == true {
|
||||
fmt.Println("prime")
|
||||
} else {
|
||||
fmt.Println("not prime")
|
||||
}
|
||||
}
|
||||
// I will write it again for now this code is written by the lecturer
|
2
main.go
2
main.go
|
@ -11,5 +11,5 @@ func main() {
|
|||
variables.Demo1()
|
||||
fmt.Print()
|
||||
conditionals.Demo3()
|
||||
loops.Demo3()
|
||||
loops.Demo4()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue