Enter a prime number of 1-

Source: Internet
Author: User

Prime number. In a natural number greater than 1, except for 1 and the integer itself, it cannot be divisible by other natural numbers. Or among all integers greater than 1, except 1 and itself, there are no other factors. Such integers are called prime numbers or prime numbers. In other words, only the natural numbers of two positive factors (1 and itself) are prime numbers. A number larger than 1 but not a prime number is called a union number. 1 and 0 are both non-prime numbers and non-composite numbers. Prime numbers play an important role in number theory.

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;

Namespace Sushu
{
Class Program
{
Static void main (string [] ARGs)
{
Int statue = 0;
Console. writeline ("output all prime numbers of 1-10000 ");
For (INT I = 2; I <= 10000; I ++)
{
For (Int J = 2; j <I; j ++)
{
If (I % J = 0)
{
Statue = 0;
Break; // jump out of this loop
}
Else
{
Statue = 1;
}
}
If (statue = 1)
{
Console. Write (I + "");
}

}
Console. Readline ();
}
}
}
Method 2:
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;

Namespace zhishu
{
Class Program
{
Static void main (string [] ARGs)
{
Int state = 0;
Int I;
Console. writeline ("output prime numbers between 1 and ");
For (I = 2; I <= 100; I ++)
{
For (Int J = 2; j <math. SQRT (I); j ++)
{
If (I % J = 0)
{
State = 0;
Break;
}
Else
{
State = 1;
}
}
If (State = 1)
{
Console. Write (I + "");
}
}

Console. readkey ();
}
}
}
The second method is more efficient.

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.