【PAT练习随笔】——素数和

 

 

代码实现:

#include <stdio.h>



int main(int argc, char **argv) {

    int a=0,b=0,c=0;

    int mark=0,index=0;

    int j=2,k=0;

    

    scanf("%d %d",&a,&b);

    

    if(a>b){

        c=b;

        b=a;

        a=c;

    };

    

    c=0;

    

    while(1){

        

        mark=1;

        k=2;

        while(k<j){

            if(j%k){

                k++;

                continue;

            }else{

                mark=0;

                break;

            };

        };

        if(mark==1){

            index++;

            if(index>=a&&index<=b){

                c+=j;

                if(index==b){

                    goto P1;

                };

            }

        };

        

        j++;

    };

    

    P1:

    printf("%d",c);

    

    return 0;

}

 

posted on 2021-11-18 10:00  撞破南墙不回头  阅读(34)  评论(0)    收藏  举报

导航