# Passing functions using arrays

Hi,

I need help creating a function using arrays and passing it to main. I've attached what I know so far:

// 12.1.cpp : Defines the entry point for the console application.
//Modified program to generate a table of prime numbers

#include "stdafx.h"

int my_prime (int prime []);

int main ()
{
int ans;
int result = my_prime(ans);

result;

return 0;
}

int my_prime (int p [])
{
int p, is_prime, i, primes[50], prime_index = 2;

primes[0] = 2;
primes[1] = 3;

for      (p=5; p<=50; p=p+2)

{ is_prime =1; //equal to primes[1]=3

for (i=1; is_prime && (p/primes[i] >= primes[i]); ++i)

if ( p % primes[i] == 0) //if no remainder do this
is_prime = 0; //setting is_prime equal to primes[0]=2

if (is_prime) //if expression is true
{
primes[prime_index] = p;
++prime_index;

}
}
}
F. Dominicus

membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have not idea why this topic should be deleted. I wrote an answer and well I'd expect at least some feedback about it.

Regards
Friedrich
amlegacy

I'm sorry I didn't understand the answer. I thought it would be best for me to re-word the question.

Your solution was good because I wasn't specific about my question. You took the time to answer the question. I'm sorry that I didn't get back to you sooner.
I suggested you wrote another function which tests a number on primeality.
Then you run a loop to fill the primes array.

and I wrote that the comments about the use if is_prime doe not mean what the code does.

Regards
Friedrich