# Print prime numbers with prime sum of digits in an array

CServer Side ProgrammingProgramming

Given with an array of elements and the task is to print those numbers whose digit sum is also prime and return -1 is not such digit exists in an array

Input: arr[]={2,4,3,19,25,6,11,12,18,7}
Output : 2, 3, 25, 11, 12, 7

Here, the given output is generated as it contains those additive numbers whose sum is also prime like − 2, 3, 7 are prime but 25(2+5=7), 11(1+1=2), 12(1+2=3) are also prime whereas numbers like 19(1+9=10) are not prime.

## Algorithm

START
Step 1 -> Take array of int with values
Step 2 -> declare start variables as i, m, flag, flag1, sum, r, d, j, tem
Step 3 -> store size of array in m as sizeof(arr)/sizeof(arr)
Step 4 -> Loop For i=1 and i<m and i++
Set flag=flag1=sum=0
Set d=int(arr[i]/2
Loop For j=2 and j<=d and j++
IF arr[i]%j==0
Set flag=1
Break
End IF
End
IF flag=0
Set tem=arr[i]
Loop While tem
Set r=tem%10
Set sum=sum+r
Set tem=tem/10
End
Set d=int(sum/2)
Loop For j=2 and j<=d and j++
IF sum%j=0
Set flag1=1
break
End
End
IF flag1=0
Print arr[i]
End
End
End
STOP

## Example

#include<iostream>
using namespace std;
int main(){
int arr[]={2,4,3,19,25,6,11,12,18,7};
int i,m,flag,flag1,sum,r,d,j,tem;
m=sizeof(arr)/sizeof(arr);
for(i=0;i<m;i++) {
flag=flag1=sum=0;
d=int(arr[i]/2);
for(j=2;j<=d;j++){
if(arr[i]%j==0) {
flag=1;
break;
}
}
if(flag==0) {
tem=arr[i];
while(tem) {
r=tem%10;
sum=sum+r;
tem=tem/10;
}
d=int(sum/2);
for(j=2;j<=d;j++) {
if(sum%j==0){
flag1=1;
break;
}
}
if(flag1==0){
cout<<arr[i]<<" ";
}
}
}
}

## Output

if we run the above program then it will generate the following output

2 3 11 25 12 7
{"ft_lang_label":"__label__en","ft_lang_prob":0.5410842,"math_prob":0.9972864,"size":1522,"snap":"2021-43-2021-49","text_gpt3_token_len":558,"char_repetition_ratio":0.11067194,"word_repetition_ratio":0.032786883,"special_character_ratio":0.41458607,"punctuation_ratio":0.16083916,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9998863,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-21T17:43:14Z\",\"WARC-Record-ID\":\"<urn:uuid:6608d824-3c20-4f1d-9725-33332b192641>\",\"Content-Length\":\"33370\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:39cb3c4c-e778-4b3c-a0c5-510fe3b67084>\",\"WARC-Concurrent-To\":\"<urn:uuid:a23a316c-c96c-48e2-8842-ee110bbda5fe>\",\"WARC-IP-Address\":\"72.21.91.42\",\"WARC-Target-URI\":\"https://www.tutorialspoint.com/print-prime-numbers-with-prime-sum-of-digits-in-an-array\",\"WARC-Payload-Digest\":\"sha1:VBHSZGPK3K6TEQCYKWZL6LNGL3XJUPXB\",\"WARC-Block-Digest\":\"sha1:5EM75MMGYK5RF6OXUYOOC5CJF37XPDCQ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585439.59_warc_CC-MAIN-20211021164535-20211021194535-00372.warc.gz\"}"}