#include <stdio.h>
int main(void)
{
int i, no;
int prime[500];
int ptr = 0;
unsigned long counter = 0;
prime[ptr++] = 2;
prime[ptr++] = 3;
for(no=5;no<=1000;no+=2)
{
for (i = 1;i < ptr;i++)
{
counter++;
if (no%prime[i] == 0)
break;
}
if (ptr == i)
prime[ptr++] = no;
}
for (i = 0;i < ptr;i++)
printf("%d\n",prime[i]);
printf("乘除运算的次数:%lu\n", counter);
return(0);
}
认真学习的大头
浏览 1228回答 1
1回答
朕日理万机
prime[ptr++] = no; 这一句。而且你这么贴代码好难看,不是有代码的粘贴工具吗#include <stdio.h>
int main(void) {
}