当前位置:网站首页>Find all prime numbers between 100 and 200

Find all prime numbers between 100 and 200

2022-06-22 12:09:00 Sainbo

#include<stdio.h>
#include<windows.h>

// Solutions ,i Set initial value 100 It is accumulated after not counting once , Because prime numbers only have 1 And its two prime numbers , set up t For 1 and i Divisor other than itself , If the integer is false 0, End in turn . Otherwise it's true 1, If one time is true, the output is stopped , Avoid multiple t Divided by i Repeat output
void test1()
{
    int i, t;
    for(i = 100; i <= 200; i++) 
    {
        for(t = 2; t < i; t++)
        {
            if(i % t == 0) break;
            else  
                printf("%d、", i);   /* The test uses Chinese registration number , feasible */
            break;
        }
    }
    printf(" Prime number !\n");
}

void test2()
{
    int i = 100, t = 2;
    while(i < 200)
    {
        i++;
        while(t < 199)
        {
            
            if(i % t == 0) break;
            else if(i % t == 1) printf("%d  ", i);
            break;
            t++;
        }
    }
    printf(" Prime number \n");
}

void test3()
{
    int i = 100, t = 2;
    do
    {
        i++;
        do
        {
            if(i % t == 0) break;
            else if(i % t == 1) printf("%d  ", i);
            break;
            t++;
        } while(t < 199);
    } while(i < 200);
    printf(" Prime number \n");
}
void main()
{
    test1();
    test2();
    test3();
    system("pause");
}

原网站

版权声明
本文为[Sainbo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221133239004.html