"C语言设计:输入两个数,输出两数之间的素数及其个数,输出要求每5个数一换行"

2024-12-30 22:25:51
推荐回答(1个)
回答1:

#include
#include

int main(void)
{
int m = 0, n = 0, i = 0, sum = 0;

printf("请输入起始数m = ");
scanf("%d", &m);
printf("请输入中指数n = ");
scanf("%d", &n);

while(++m < n)
{
for(i = 2; i <= sqrt(m); i++)
{
if(m % i == 0)
break;
else
continue;
}

if(i > sqrt(m))
{
if(sum % 5 == 0)
printf("\n");
printf("%4d ", m);
sum++;
}

}

printf("\n");

return 0;
}