用C语言编写程序求出100以内的素数,并将这些数在屏幕上5个一行的显示出来

2024-11-22 19:38:58
推荐回答(1个)
回答(1):

#include
char rec[101];
int main()
{
int i, j, count = 0;
for(i = 2; i <= 10; i++)
{
if(rec[i])continue;
for(j = 2; j * i <= 100; j++)rec[i * j] = 1;
}
for(i = 2; i <= 100; i++)
{
if(rec[i])continue;
printf("%d", i);
if((++count) % 5 == 0)printf("\n");
else
printf(" ");
}
return 0;
}