I need to complete the task, meeting the following requirements: Algorithms for input and output of array elements, as well as for performing a given operation on an array, should be formatted as functions. When accessing array elements, use a pointer.
In principle, my program should work, but it works only for 1 number, for 2 it already shows some kind of weird, and for 3 or more - nothing at all.
#include <iostream>
#include <stdlib.h>
using namespace std;
void input(int x[], int n);
int spisok(int x[], int n);
int main() {
int n, x[n];
cout << "Vvedite kolichestvo chisel v massive" << endl;
cin >> n;
input(x, n);
spisok(x, n);
for (int i = 0; i < n; i++) {
if (x[i] != 0) {
cout << "Prostiye chisla " << x[i] << ' ';
}
}
return 0;
}
void input(int x[], int n) {
int * p = x;
for (int i = 1; i <= n; i++) {
cout << "Vvedite " << i << "-oe chislo" << endl;
cin >> * p;
p++;
}
}
int spisok(int x[], int n) {
int i = 0;
for (int j = 2; j <= x[i]; j++) {
if (i > n) {
break;
}
if (x[i] % j == 0 && x[i] != j) {
x[i] = 0;
break;
}
i++;
}
return *x;
}