If You know the required precision, You can calculate the right value for the maximum value for n before You start the loop. Second thing: start with the most less number if You start adding all delta values.
Similar to this
int ndigits;
cout << "How many digits?" << endl;
cin >> ndigits;
int n = int( pow( double(10), double(ndigits)/2 ) + 0.5 );
long double Pi2 = 0;
int i = 1;
for( int i=n; i>0; --i )
{
if ((i%2) == 1) {
Pi2 += 1/pow(long double(i),2);
}
else {
Pi2 -= 1/pow(long double(i),2);
}
}
Pi2 *= 12;