⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1027.c

📁 用于学习的C原程序
💻 C
字号:

/*********************************************************************
 * a demo program which to find all the prime numbers from an array  *
 * Input : N, and N numbers a[100]                                   *
 * output: all the prime number and the sum of them                  *
 *                                                                   *
 * Date: 20th April, 2007                                            *
 *       by ZQ                                                       *
 *********************************************************************/
 
#include <stdio.h>
int main()
{
    //declare N and an array a[100] for N numbers of integer 
    int N,a[100],b[100];
    //declare the result variable
    int s;
    //declare the loop variables
    int i,j,k;
    
    /* input N and N numbers of integer from keyboard */
    
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&a[i]);
    }
    
    /* find the prime number and add them to s*/
    
    s=0;
    for(i=0;i<N;i++)
    {
        for(j=2;j<=sqrt(a[i]);j++)
        {
            if(a[i]%j==0) // it means a[i] has a fact of j, it is not a prime number */
                break;
        }//end of loop j
        
        // it means end from the for-loop, not break from the for-loop  
        if(j>sqrt(a[i]))
        {
            s+=a[i];
            b[k]=a[i];
            printf("%d ",b[k]);
            k++;
         }//end of if(...)
    }// end of loop i
    
    /* output the result */
    
    printf("\ns=%d\n",s);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -