You and your two friends are working in a multinational company. How can you three find out the average salary of you all without disclosing your own salary to the other two ?
Let us say that the three people are A, B and C respectively. Now you, A will tell the sum of your salary and a random number to B.
SA (Actual Salary) + A (random number of A)
In the same manner your friend B, will add his salary with a random number to the amount given by A (you) and will pass it to C.
(SA + A) + (SB + B)
C will do the same.
(SA + A) + (SB + B) + (SC + C)
Now C will pass this total amount to A. He will subtract his random number from the amount and it will become:
(SA) + (SB + B) + (SC + C)
Then he will pass it to B and B will subtract his random number from the amount.
(SA) + (SB) + (SC + C)
Then he will pass this to C who will subtract his random number.
(SA) + (SB) + (SC)
Now C has the total amount of their combined salaries. He will tell the amount to all of you and you can easily divide it by 3 to get the average salary.