Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "strconv"
- )
- func main() {
- var input string
- fmt.Scanln(&input)
- var primeSum = 0
- var nonPrimeSum = 0
- for ; input != "stop"; {
- var number, _ = strconv.Atoi(input)
- if number >= 0 {
- if number % 2 == 0 || number % 3 == 0 || number % 5 == 0 {
- if number == 2 || number == 3 || number == 5 || number == 7 {
- primeSum += number
- } else {
- nonPrimeSum += number
- }
- } else {
- primeSum += number
- }
- } else {
- fmt.Println("Number is negative.")
- }
- fmt.Scanln(&input)
- }
- fmt.Printf("Sum of all prime numbers is: %d\n", primeSum)
- fmt.Printf("Sum of all non prime numbers is: %d\n", nonPrimeSum)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement