求出100~200之间的全部素数,每行输出8个数,每个数宽度为5列。
输出格式:
每行输出8个素数数,每个素数宽度为5列。
输出样例:
101 103 107 109 113 127 131 137
139 149 151 157 163 167 173 179
181 191 193 197 199
程序代码:
#include<stdio.h>
#include<math.h>
int main()
{
int a,i,j,count=0;
for(i=100;i<=200;i++)
{
int tag=0;
a=(int)sqrt(i);
for(j=2;j<=a;j++)
{
if(i%j==0)
{
tag=1;
break;
}
}
if(tag==0)
{
printf("%5.0d",i);
count++;
if(count%8==0)
{
printf("\n");
}
}
}
return 0;
}
本文介绍了一个C语言程序,用于计算并按每行8个数、5列宽度的方式输出100到200之间的所有素数。程序通过嵌套循环和取整平方根的方法来判断素数。
4078

被折叠的 条评论
为什么被折叠?



