例4-10 输出100之内的素数——循环镶嵌

例4-10 输出100之内的素数——循环镶嵌

程序核心——镶嵌

程序


#include<stdio.h>
#include<math.h>
int main()
{
	int count,i,m,n;
	
	count=0;
	for(m=2;m<=100;m++)
	{
		n=sqrt(m);
		for(i=2;i<=n;i++)
		{
			if(m%i==0)
			{
				break; 
			}
		}
		if(i>n)
		{
			printf("%6d",m);
			count++;
			if(count%10==0)
				printf("
");
		}
	}
	printf("
"); 
	return 0;
 } 

结果

     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

--------------------------------
Process exited after 0.3373 seconds with return value 0
请按任意键继续. . .


分析

重点:镶嵌

原文地址:https://www.cnblogs.com/5236288kai/p/10660150.html