Three Employees want to know the average of their salaries. They are not allowed to share their individual salaries.
Answer:
1) X adds a Random Number and his salary and tells the sum to Y.
2) Y also adds a Random Number and his salary to the sum told by X and tells new sum to Z.
3) Z also adds a Random Number and his salary to the sum told by Y and tells new sum to X.
4) X subtracts its random number from the sum told by Z and tells the new number to Y.
5) Y subtracts its random number from the sum told by X and tells the new number to Z.
6) Z subtracts its random number from the sum told by Y and announces the new number.
The new number is now the sum of three salaries and average can be calculated by dividing the sum by 3.
Finally, nobody knows the salary of others, but all know average.
This can be extended to more than 3 employees also.
This article is contributed by Shivam .
VIDEO
Learn to code easily with our course
Coding for Everyone . This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
19 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Add Your Comment
Please Login to comment...