Write a C program that solve the n-ball problem; given any number of balls, you have to tell how many times you have to weigh at minimum to find which ball is the heavier one. Also your code should display the 3 splits of n balls. Make sure that your code handles properly all values of n, not only those that are multiples of 3.
For n=8, min_weigh = 2 and pan1=3, pan2=3, remaining=2.
For n=13, min_weigh = 3 and pan1=5, pan2=5, remaining=3.
CODE:
#include<stdio.h>
main()
{
int n,i,l,div;
printf("enter number");
scanf("%d",&n);
i=n/2;
i-=1;
l=i+i;
div=n-l;
printf("min-weight:-%d",div);
printf("Pan1:-%d,Pan2:-%d",i,i);
printf("rema:-%d",div);
return 0;
}
Program Output:
For more problems click here
No comments:
Post a Comment