Helo!
Please, what is wrong wiht the code?
If I out a1=400, it writes out 19, a si t should be.
But, if I write 484, then it writes out NOTHING!!!
it should wirte out closest prime number to sqrt(a1).
For sqrt(400)=20, nearest prime is 19, and it writes it out.
But for sqrt(484)= 22, nearest pirme would be 23, and it writes nothing.
please, where is the mistake?
Many thanks!
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

#include<iostream>
#include<math.h>
using namespace std;
int Ave(int array_f[], int& sm, int c)
{
int k=0;
do {
int e=1;
for (int i=2;i<sm;i++)
{
if (sm%i==0)
{
e=0;break;
}
}
if (e==1) {
array_f[k]=sm; /*cout<<k<<" "<<sm<<" "<<array_f[k]<<endl;*/k=k+1;
}
sm=sm+1;
} while(k<5);
/*int r;
int m=0;
for (int i=0;i<k; i++) {
m=array_f[i]+m;
}
r=m/k;
*/
cout<<array_f[0]<<" "<<array_f[1]<<" "<<array_f[2]<<" "<<array_f[3]<<" "<<array_f[4]<<endl;
if (c<array_f[0]){
cout<<array_f[0]<<endl;
}
if (c>array_f[4]){
cout<<array_f[4]<<endl;
}
for (int j=0;j<k;j++) {
if ((c>array_f[j])&&(c<array_f[j+1])) {
if (carray_f[j]<=array_f[j+1]c){
cout<<array_f[j]<<" "<<"@"<<endl;
}
else {
cout<<array_f[j+1];
}
}
}
return r;
} //function
int main()
{
int a1=484;
int a=(int)sqrt(a1);
int x=14;
int array_m[5];
int g;
g=Ave(array_m,x,a);
cout<<g;
system("PAUSE");
return 0;
}
 