Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to know the average without disclosing the salaries?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 742
    Comment on it

    Suppose we want to find the average salary of three employee(A,B,C) without disclosing there individual salary.In order to do this see the following algorithm:

    ALGORITHM :

    1. First A will add a random number to it's salary and then tell the total sum to B.
    2. B will add its salary to the sum told by A and tell the new sum to C.
    3. C will also add its salary to the sum told by B and tell the new sum to A.
    4. A will now subtract its random number from the sum.
    5. Now we have a new number which is the total of all three employee salary.
    6. We will take average by dividing total buy 3.

    PROGRAM :

    int main(){
    int a=10,b=20,c=30,avg=0;
    int x=1;
    //printf("Enter the first number:::");
    //scanf("%d",&a);
    //printf("Enter the second number:::");
    //scanf("%d",&b);
    //printf("Enter the first number:::");
    //scanf("%d",&c);
    
    a=x+a;
    b=a+b;
    c=b+c;
    
    a=c-x;
    avg=a/3;
    printf("total sum ::: %d",a);
    printf("\naverage ::: %d",avg);
    
    return 1;
    }

    OUTPUT :

    total sum ::: 60
    average ::: 20

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: