Răspuns:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n,i;
cin >> n;
int v[n], ap[n];
for (i=0; i<n; i++) cin >> v[i];
int a,b;
for (i=0; i<n; i++) {
a=sqrt(v[i]);
ap[i]=v[i]-a*a;
b=(a+1)*(a+1)-v[i];
if (b<ap[i]) ap[i]=b;
}
int apmin=ap[0];
for (i=1; i<n; i++) {
if (ap[i]<apmin) apmin=ap[i];
}
cout << "apropiere minima de " << apmin << " o au elementele: ";
for (i=0; i<n; i++) {
if (ap[i]==apmin) cout << v[i] << " ";
}
return 0;
}
Explicație: