To print out the primes from the previous question, use
-
cout << primes[3] << ' ';
-
if (i<=3) cout << primes[3] << ' ';
-
if (i<=3) cout << primes[i] << ' ';
-
for (i=0; i<3; i++) cout << primes[3] << ' ';
-
for (i=0; i<3; i++) cout << primes[i] << ' ';
-
i=0; while (i<3) cout << primes[++i] << ' ';
-
i=1; while (i<3) cout << primes[i++] << ' ';
The following program is intended to print out the primes ``1 2 3
5 7 11 13 17 19 23'':
#include <iostream.h>
void print_primes(int array[], int size)
{
int i;
for (i=0; i<size; i++) cout << array[i] << " ";
}
void main(void)
{
int primes[10] = {1, 2, 3, 5, 7, 11, 13, 17, 19, 23};
print_primes(primes, 10);
}