SureshMac:GoExamples suresh$ go run prime1.goĮnter the Number to find the Prime Numbers = 35ģ5 is Not a Prime Number Go Program to Check the Number is Prime using Functions package main } SureshMac:GoExamples suresh$ go run prime1.goĮnter the Number to find the Prime Numbers = 2 package mainįmt.Print("Enter the Number to find the Prime Numbers = ")įmt.Println(primNum, " is a Prime Number")įmt.Println(primNum, " is Not a Prime Number") If True, it is a prime number otherwise, not a prime. If True, increment the count value, and the break statement will exit the GC from for loop.Īfter the for loop, we used the If else statement (if primcount = 0 & primNum != 1) to check the count value equals zero and the number does not equal 1. This Go program uses for loop (for i := 2 i < primNum/2 i++) that starts at two and ends at number/2, and If statement (if primNum%i = 0) examines the number divisible by the iterator value. Write a Go Program to Check Prime Number. Remember, 2 is the only even prime number. Any number can be a Prime number if it is not divisible by different numbers beside one and itself.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |