• 素数---小修改2


    #include<stdio.h>
    int main()
    {
        int n,a,b,i;
        int sum=0   ;
    
        scanf("%d%d",&a,&b);
        {
            for (n=a;n<=b;n++)
            {
                for (i=2;i<=n-1;i++)
                    if (n%i==0) break;
                if (i>=n)
    
    
                    sum+=n;
            }
            printf("%d",sum);
            printf("
    ");
        }
    }
    View Code

    #include<stdio.h>
    int main()
    {
    int n,a,b,i;
    int sum=0 ;

    scanf("%d%d",&a,&b);
    {
    for (n=a;n<=b;n++)
    {
    for (i=2;i<=n-1;i++)
    if (n%i==0) break;
    if (i>=n)


    sum+=n;
    }
    printf("%d",sum);
    printf(" ");
    }
    }

    #include<stdio.h>
    int main()
    {
        int n,a,b,i;
        int sum=0   ;
    
        while ( scanf("%d%d",&a,&b)==2)
        {
            for (n=a;n<=b;n++)
            {
                for (i=2;i<=n-1;i++)
                    if (n%i==0) break;
                if (i>=n)
    
    
                    sum+=n;
            }
            printf("%d",sum);
            printf("
    ");
        }
    }
    View Code

    #include<stdio.h>
    int main()
    {
    int n,a,b,i;
    int sum=0 ;

    while ( scanf("%d%d",&a,&b)==2)
    {
    for (n=a;n<=b;n++)
    {
    for (i=2;i<=n-1;i++)
    if (n%i==0) break;
    if (i>=n)


    sum+=n;
    }
    printf("%d",sum);
    printf(" ");
    }
    }

     

    ****************************************************************************************************************************************

    #include<stdio.h>
    int main()
    {
        int n,a,b,i;
        int j,s;
        int c[1000];
      while ( scanf("%d%d",&a,&b)==2)
        {
            j=0;
            for (n=a;n<=b;n++)
            {
                for (i=2;i<=n-1;i++)
                    if (n%i==0) break;
                if (i>=n)
                
                    c[j++]=n;
               
            }
           
            
             s=0;
            for (i=0;i<j;i++)
                s=s+c[i];
            printf("%d
    ",s);
        }
        return 0;
    }
    View Code

    #include<stdio.h>
    int main()
    {
    int n,a,b,i;
    int j,s;
    int c[1000];
    while ( scanf("%d%d",&a,&b)==2)
    {
    j=0;
    for (n=a;n<=b;n++)
    {
    for (i=2;i<=n-1;i++)
    if (n%i==0) break;
    if (i>=n)

    c[j++]=n;

    }


    s=0;
    for (i=0;i<j;i++)
    s=s+c[i];
    printf("%d ",s);
    }
    return 0;
    }

  • 相关阅读:
    Server Profiler
    Unit Test with VS.NET
    js解析json字符
    多维数组
    $routeProvider与$stateProvider区别
    post 与get
    gulp配置
    homebrew常用指令
    less.js
    过滤器
  • 原文地址:https://www.cnblogs.com/2014acm/p/3901206.html
Copyright © 2020-2023  润新知