The running program is as follows: the program implements the output of all prime numbers not less than n; 10 lines

Continue the previous article; the running program is as follows

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int prime(int m)
{
    int i;
    if(m == 0) return 0;
    if (m == 1) return 0;
    for (i = 2; i <= sqrt(m*1.0); i++)//有等号 
    if (m%i == 0) break;
    if (i <= sqrt(m*1.0)) return 0;//是素数 
    else return 1;//不是素数 
}
int main()
{
    int n, i, j=0;
    printf("n:");
    scanf("%d", &n);
    printf("小于%d的素数为:\n", n);
    if (n > 2)
    {printf("%4d", 2);
    j++;
    }
    for (i = 3; i <= n; i += 2)
        if (prime(i) == 1)
        {
            printf("%4d", i);
            if (j != 0 && ++j % 10 == 0)
                printf("\n");

        }

        printf("\n");
        system("pause");
        return 0;

}

write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325608662&siteId=291194637