getting residue of linear regression

Please avoid using the matlab-tag if your question is with regards to c++.

In your case, a simple for-loop would do it

int residue = 0;
for (i=0;i<n;i++)
{
     y_fit[i]=Slope*x[i]+Intercept; 
     residue += (y[i] - y_fit[i])*(y[i] - y_fit[i]);
}