求1~100之间的质数。

#include<stdio.h>
int main()
{
    int i=2;
    int t=1,j;
    printf("%-6d",i);
    for (i=3;i<=100;i=i+2)
    {
        for (j=2;j<=i-1;j++)
        {
            if (i%j==0)
                break;
        }
        if (i==j)
         {
         printf("%-6d",i);
   t++;
   if(t%5==0)                                   //每行5个。
   printf("\n"); 
   }
        }
          return 0; 
}

猜你喜欢

转载自blog.csdn.net/qq_42387291/article/details/80725836