Average array elemets value-+prime numbers<=b in the same function,-PLEASE URGENT!!!

Hello!

I have to write function Average, which has TWO PARAMETERS, array and int.
The same function has to:

1. find 5 prime numbers >= int,
2. make array_f[5] (RIGHT THOSE 5 prime numbers from (1).)
3. count average value of all 5 prime numbers (eements)
4, return that average value to main

I am trying to all possible ways,

the basic problem is how to put ALL THAT TO SAME FUNCTION???

I appoligise, am absolute beginner, and still have to practise with that!
Please, if smone can help!!!
MANY THANKS!




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream> 

using namespace std;

int Prime (int st) 
{
    if (st<2)
        return 0;
        
    int e = 1;
    for (int i=2; i<st; i++)
    {
        if (st%i==0)
        {
            e = 0;
            break;
        }
    }

    return e;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
int Average(int array_f[5], int st){
int m=0;
int k=0;
int e=1;
for (int i=2; i<st; i++){
if (st%i==0)
{
e=0;
break;
}


}


if(e==1){array_f[k]=st;}
k+=1;
m+=st/5;
st+=1;


}// do
while(k==4);
return m;
}

int main(){
int b=23;
cout<<Prime(b);
return 0;
}
Last edited on
Topic archived. No new replies allowed.