+ 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?

29th Jun 2017, 12:39 AM
RZK 022
+ 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
29th Jun 2017, 7:04 AM
Gaurav Sukhatme
+ 4
correct but you need to prove it by making a code
29th Jun 2017, 1:04 AM
RZK 022
+ 2
3 kids
29th Jun 2017, 1:03 AM
Nirmal Kumar Bhakat
+ 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
29th Jun 2017, 5:03 AM
Flandre Scarlet
+ 2
writing it as a code: public int Solution(ave1, ave2, age){ return (age - ave1)/(ave1 - ave2) -1 }
29th Jun 2017, 5:07 AM
Flandre Scarlet
+ 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
29th Jun 2017, 1:04 AM
Nirmal Kumar Bhakat
+ 1
okay
29th Jun 2017, 1:05 AM
Nirmal Kumar Bhakat
+ 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 :)
1st Jul 2017, 5:56 AM
Rakowiecki Ryszard