# Answer to Question #47754 in C++ for arundhati

Question #47754

C++ program to print the sum of prime numbers in an array.

Expert's answer

**Solution.**

//Connectinglibrary

#include"stdafx.h"

#include<stdlib.h>

#include<iostream>

usingnamespace std;

//Functioncomputing the sum of prime numbers

intFuncSum(int* a,intsize)

{

intsum=0;

boolbState=true;

for(int i = 0; i < size; i++)

{

for(int j = 2; j <a

*; j++)*

{

if(a[i]% j == 0)

{

bState=false;

break;

}

}

if(a[i]>1&& bState)

{

sum+=a[i];

}

}

returnsum;

}

//Themain function

intmain()

{

inta[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 4, 6, 9};//array

cout<<"Amountof prime numbers in an array: "<<FuncSum( a,sizeof(a)/sizeof(a[0]))<<endl;

//system("pause");

return 0;

}

[i]

{

if(a[i]% j == 0)

{

bState=false;

break;

}

}

if(a[i]>1&& bState)

{

sum+=a[i];

}

}

returnsum;

}

//Themain function

intmain()

{

inta[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 4, 6, 9};//array

cout<<"Amountof prime numbers in an array: "<<FuncSum( a,sizeof(a)/sizeof(a[0]))<<endl;

//system("pause");

return 0;

}

[i]

``

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment