+ 3
A logic puzzle . Can you solve it .
The average age of a familyâmade up of two parents with kidsâis 20. If you exclude one parent, who is 40, the average age drops to 15. How many kids are in the family?
8 RĂ©ponses
+ 2
import java.util.*;
public class Program
{
public static void main(String[] args)
{
int age,avg1,avg2,n,child;
Scanner sc=new Scanner(System.in);
System.out.println("Enter age of a parent,avg1,avg2\n");
age=sc.nextInt();
avg1=sc.nextInt();
avg2=sc.nextInt();
n=(age-avg2)/(avg1-avg2);
child=n-2;
System.out.println("No. of child="+child);
}
}
https://code.sololearn.com/cSb1Vef8gwd6/?ref=app
+ 4
correct but you need to prove it by making a code
+ 2
3 kids
+ 2
we can think this problem like this:
the 40-aged parent give each of others 5 ages to reach 20, then he (or she) can give 4 times, including another parent, so there are 3 kids
+ 2
writing it as a code:
public int Solution(ave1, ave2, age){
return (age - ave1)/(ave1 - ave2) -1
}
+ 1
In total there are 5 persons in the family .
Total age = 5*20=100
When you remove one parent
Total age of 4 persons = 60
avg=60Ă·4=15
+ 1
okay
+ 1
40 ăăă age of one parent
n - Number of others members of The family
n-1 number of children
x ăă mean of n members of a family without 40
x=15 ăăă KNOWN
(40+n*x)/(n+1) ăă mean of all members
Solution
ăă
(40+n*x)/(n+1)=20 / *(n+1)
40+n*x=20*(n+1)
40+n*x= 20n+ 20
40 + n *15 = 20n + 20 / -15n-20
20= 5n / :5
4 = n / - second parent
3 = n-1 ăăă Number of children in a family
n-1 ăăă Number of children ăăă 3 :)