int prime(int d){
int e=0;
do
{
for (int i=2;i<d;i++){
if (d%i==0){e=e;}
else{e+=1;}
d+=1;
cout<<e<<endl;
}
}
while(e!=0);
return d;
}
int main(){
int c=5;
cout<<prime(c);
return 0;
}
bool is_prime(unsignedint n)
{
if (n == 0 || n == 1)
returnfalse;
if (n == 2)
returntrue;
for (unsignedint i=2; i < n; ++i)
if (n % i == 0)
returnfalse;
returntrue;
}
Now all you need to do is use the test to find 20 prime numbers, greater than 6.
This could be written like:
1 2 3 4 5 6 7 8 9 10
unsignedint n=6;
while (/* we don't have 20 numbers */)
{
if (is_prime(n))
// add n to list of primes (or print it)
// numbers found += 1
++n:
}
d is a junk value.
e = e; Why is that in there?
I still find your formatting horrible and confusing and it makes it difficult to see errors tbh. The whole code just looks wrong and like a mess. It would also be helpful if you said what errors you were getting during runtime or compilation.
Anyway, you should do this:
Declare an integer equal to 7.
Check if all integers 2 up to (n - 1) divide n.
If none of them do, print the number. Increment a counter of how many numbers were printing.
Increment n.
Continue doing this until you have printed 20 numbers.
The problem is,I have to save them in an array as elements.
The same functin is then computing the average value of the 20elements and returns that value with return.
I do not know how to do it.
We have only example that array is filled in main, not in function.
int Prime (int array_[5], int st) {
int array_f[5];
int m=0;
int k=0;
do
{
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;
}