Sum of prime numbers

Source: Internet
Author: User

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

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• Sales Support

1 on 1 presale consultation

• After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.