We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
floatCALC(vector<int>X,vector<int>Y,intn){intsum_X=0,sum_Y=0,sum_XY=0;intsquareSum_X=0,squareSum_Y=0;for(inti=0;i<n;i++){// sum of elements of array X. sum_X=sum_X+X[i];// sum of elements of array Y. sum_Y=sum_Y+Y[i];// sum of X[i] * Y[i]. sum_XY=sum_XY+X[i]*Y[i];// sum of square of array elements. squareSum_X=squareSum_X+X[i]*X[i];squareSum_Y=squareSum_Y+Y[i]*Y[i];}// use formula for calculating correlation coefficient. floatcorr=(float)(n*sum_XY-sum_X*sum_Y)/sqrt((n*squareSum_X-sum_X*sum_X)*(n*squareSum_Y-sum_Y*sum_Y));returncorr;}
Why this function somethimes right result sometime invalid results.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 5: Computing the Correlation
You are viewing a single comment's thread. Return to all comments →
Why this function somethimes right result sometime invalid results.