求100以内所有的质数
5个回答
2013-09-25
展开全部
质数的定义应为:一个大于1的自然数,除了1与它自身外,再没有其它的正约数了,这样的自然数叫做质数。 互质,又称互素。若N个整数的最大公因子是1,则称这N个整数互质 素数,或称质数,是只能被1或者自己整除的自然数。最小的素数是2,而最大的素数并不存在,这一点欧几里德已在其《几何原本》中证明。 围绕素数存在很多的数学问题、数学猜想、数学定理,较为著名的有孪生素数猜想、哥德巴赫猜想等等。 素数序列的开头是这样: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97
2013-09-25
展开全部
你好!!<参考代码:由小到大找出制定数目的素数>
#include <stdio.h>
#define MAXSIZE 100
#define YES 1
#define NO 0
void main(void)
{
int prime[MAXSIZE]; /* array to contains primes */
int gap = 2; /* increasing gap = 2 and 4 */
int count = 3; /* no. of primes */
int may_be_prime = 5; /* working variable */
int i, is_prime;
prime[0] = 2; /* Note that 2, 3 and 5 are */
prime[1] = 3; /* primes. */
prime[2] = 5;
while (count < MAXSIZE) { /* loop until prime[] full*/
may_be_prime += gap; /* get next number */
gap = 6 - gap; /* switch to next gap */
is_prime = YES; /* suppose it were a prime*/
for (i = 2; prime[i]*prime[i] <= may_be_prime && is_prime; i++)
if (may_be_prime % prime[i] == 0) /* NO */
is_prime = NO; /* exit */
if (is_prime) /* if it IS a prime... */
prime[count++] = may_be_prime; /* save it */
}
printf("\nPrime Number Generation Program");
printf("\n===============================\n");
printf("\nFirst %d Prime Numbers are :\n", count);
for (i = 0; i < count; i++) {
if (i % 10 == 0) printf("\n");
printf("%5d", prime[i]);
}
}
#include <stdio.h>
#define MAXSIZE 100
#define YES 1
#define NO 0
void main(void)
{
int prime[MAXSIZE]; /* array to contains primes */
int gap = 2; /* increasing gap = 2 and 4 */
int count = 3; /* no. of primes */
int may_be_prime = 5; /* working variable */
int i, is_prime;
prime[0] = 2; /* Note that 2, 3 and 5 are */
prime[1] = 3; /* primes. */
prime[2] = 5;
while (count < MAXSIZE) { /* loop until prime[] full*/
may_be_prime += gap; /* get next number */
gap = 6 - gap; /* switch to next gap */
is_prime = YES; /* suppose it were a prime*/
for (i = 2; prime[i]*prime[i] <= may_be_prime && is_prime; i++)
if (may_be_prime % prime[i] == 0) /* NO */
is_prime = NO; /* exit */
if (is_prime) /* if it IS a prime... */
prime[count++] = may_be_prime; /* save it */
}
printf("\nPrime Number Generation Program");
printf("\n===============================\n");
printf("\nFirst %d Prime Numbers are :\n", count);
for (i = 0; i < count; i++) {
if (i % 10 == 0) printf("\n");
printf("%5d", prime[i]);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-25
展开全部
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 83 89 97
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-25
展开全部
2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询