C语言 4076: the sum of prime 求素数的和

Description:
Given n integer number, you should print the sum of the prime numbers in the n numbers.

Input
Each test case begin with an integer number n, then n integer numbers

Output
For each case,you should print the sum of the prime number in one line

就是说第一个数输入的是后面有几个数 第二个开始到最后一个,凡是是素数的就求和
Sample Input
2 3 5
5 1 2 3 4 5

Sample Output
8
10

请各位帮我看看我写的代码 本人非专业学生 什么都不懂 这个问题我写出来的一直都是错的 但是我不知道哪里错TAT 求指点

#include<stdio.h>
int main() 
{ 
    int n,a,sum,i,j,c;
    while((scanf("%d",&n))!=EOF)
    {
                for(i=1;i<=n;i++) 
        {
            sum=0;
                        scanf("%d",&a);
            if(a<1)
            sum+=a;
            if(a>1)
            {
                for(j=2;j<=a/2;j++)
                {
                    if(a%j!=0)  
                    sum+=a;
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}


sum=0;在for循环外面,素数大于2,素数的判断逻辑是错误的

第9行 sum=0放到for循环外边,否则sum不能到达累加值得目的啊。判断素数的处理也不对

#include<stdio.h>
int main() 
{ 
    int n,a,sum,i,j,c;
    while((scanf("%d",&n))!=EOF)
    {
        sum = 0;
        for(i=1;i<=n;i++) 
        {
            scanf("%d",&a);
            for(j=2;j<a;j++)
            {
                    if(a%j==0)
                      break;
            }
            if(j==a)
                sum += a;
        }
        printf("%d\n",sum);
    }
    return 0;
}