Do These Two Metrics Move Together?
Riverbend Supply's marketing team wants to know whether the weeks it spends more on advertising are the weeks it takes more money. Each week contributes two figures — what was spent on ads and what came in as revenue — and the two rows line up week by week. The figure the team reports is the Pearson correlation coefficient, which measures how close the relationship is to a straight line: it runs from -1, meaning revenue falls perfectly steadily as spend rises, through 0 for no straight-line relationship at all, to +1 for a perfectly steady rise.
Task: Print the Pearson correlation coefficient between the spend row and the revenue row.
Input
Three lines. The first holds a single integer n, the number of weeks. The second holds the n ad-spend figures on one line, separated by single spaces. The third holds the n revenue figures, in the same week order.
Output
One line holding the coefficient with exactly two digits after the decimal point. A negative coefficient carries a leading minus sign.
Example:
Input:
4
10 20 30 40
100 200 300 400
Output:
1.00
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in