Go language for Prime _golang within 100

Source: Internet
Author: User

This article describes the Go language screening method to find the prime number within 100. Share to everyone for your reference. The implementation methods are as follows:

Train of thought: find a non prime to dig it off, the last is the prime.
Now let's take a look at the code for Go simple.

Code inserts for Go are not currently supported, using XML instead.

Copy Code code as follows:
Package Main

Import (
"FMT"
"Math"
)

Func Main () {
var i, j, N int
var a [101]int
For i = 1; I <= 100; i++ {
A[i] = i
}
A[1] = 0
For i = 2; i < int (math. SQRT (100)); i++ {
For j = i + 1; J <= 100; J + + {
if (A[i]!= 0) && (A[j]!= 0) {
If a[j]%a[i] = = 0 {
A[J] = 0
}
}
}
}
Fmt. Println ()
For I, n = 1, 0; I <= 100; i++ {
If A[i]!= 0 {
Fmt. Print (A[i], "T")
n++
}
If n = 10 {
Fmt. Println ()
n = 0
}
}
}

I hope this article will help you with your go language program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.