Describe
Now give you n number (0<n<1000), now ask you to write a program, find out the n number of all primes, and sum.
-
Input
-
The first line gives the number of sets of test data represented by the integer M (0<m<10)
The first row of each set of test data gives you n, which represents the number of test data for that group.
The next n number is the data to be tested, with each number less than 1000
-
Output
-
Each set of test data results in a row, outputting all the prime numbers of the test data given and
-
Sample input
351 2 3 4 58 One A - - the - - -Ten + A at - - - - - in -
Sample output
Ten A the
Test code
1#include <stdio.h>2#include <stdlib.h>3#include <assert.h>4 5 intIsPrime (intnum)6 {7 intJ;8 if(num = =2)9 {Ten returnnum; One } A if(num%2==0|| Num <2) - { - return 0; the } - for(j =3; J * J <= num; J + =2) - { - if(num% J = =0) + { - return 0; + } A } at returnnum; - } - - intMain () - { - intN, I, J, M, sum; in int*A; -scanf"%d", &n); to for(i =0; I < n; i++) + { -sum =0; thescanf"%d", &m); *A = (int*)calloc(M,sizeof(int)); $ASSERT (A! =NULL);Panax Notoginseng for(j =0; J < M; J + +) - { thescanf"%d", A +j); +Sum + =IsPrime (A[j]); A } theprintf"%d\n", sum); + Free(a); - } $ return 0; $}
Sum of prime numbers