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 68 69

#include <iostream>
using namespace std;
int function(int*, int);
int function2(int*, int);
int main ()
{
int* a;
int* b;
int n;
int ok;
do
{
cout << "How much natural numbers? >>> ";
cin >> n;
cout <<endl;
a=new int[n];
for(int i=0;i<n; i++)
{
cout<< "Number " << i+1 << " >>> ";
cin>>a[i];
}
b=new int[n];
for(int j=0;j<n;j++)
{
b[j]=function(a,n);
}
cout << function2(b,n);
delete [] a;
delete [] b;
cout <<"Continue (1) End (0)?"<<endl;
cin>>ok;
}while(ok==0);
return 0;
}
int function(int* a, int n)
{
for(int j=0;j<n;j++)
for (int i=2;i<a[j];i++)
(a[j]%i==0);
}
int function2(int* b, int n)
{
for(int i=0;i<n;i++)
if(b[i] == 0)
cout<<"One of the number is 0 !";
else
cout<<"Max divisor "<< (b[i+1], b[i]%b[i+1])<<endl;
}
 
Struggled with this program for ore than 12 hours straight finally, it seems, at least to me, it's starting to somewhat work.
So the program goes like this >
cin >> n // length of first array
cin >> a[i] // I enter all numbers
First function reads the first array and returns a[i] numbers which are not primes.
New array b with the newly found results from the previous function.
Second function reads the second array and prints out max divisor of 2 numbers.
cin >>4
cin >> a[i] (6986)
function one returns 6 9 6
cin >> b[i] (696)
function2 returns 3 as the maximum number.
The problem is, it returns only 0 for me and the message that one of the numbers is 0.
I'd grately appreciate any kind of a help!
Thanks in advance!