Computer Science, asked by sreeloksree, 4 months ago

There is a Bucket of water capacity of x litres, which is supposed to fill with a mug of y millilitres water capacity. Say for example x=100 and y=10 then, bucket will get full of minimum of 8 mugs (> 80% and less than 100%>. Bucket filling is to be stopped once more than 80% of bucket capacity is filled. The amount of water taken at a time in mug is not fixed as it can be any value less than or equal to y Notify to stop once bucket is full that is more than 80% of capacity of bucket and count number of mugs poured into bucket. Note that Bucket capacity will always be greater that Mug's Capacity. Example 1: INPUT VALUES 100 this 20 // Enter Bucket capacity in litres as // Enter Mug capacity in litres as this 2 // enter amount of water in MUG one after other as below 20 20 20 20 20 .output values bucket full!no.of mugs:4 .write a problem on c,c++,java​

Answers

Answered by rohitjain92417
4

Answer:

#include <stdio.h>

int main()

{

int x=0,y=0,count=0,fill=0,cal=0,temp,flag=0;

printf("enter the Bucket and Mug capacity\n");

scanf("%d %d",&x,&y);

cal=x*0.8;

if(y>x)

{

 flag=1;

}

else  

{  

 printf("Enter Amount of water in MUG one after other as below\n");

 while(fill<cal)

 {

  scanf("%d",&temp);

  if(temp>y || temp<0)

  {

   flag=1;

   break;

  }

  else

  { fill+=temp;

   count+=1;  

  }

 }

   

}

if(flag==0)

 printf("Bucket Full \nnumber of mug %d",count);

 else

 printf("Invalid input");

return 0;

}

Explanation:

Answered by WARCRAFT8055
2

Answer:

import java.util.Scanner;

public class Bucket_tcs {

public static void main(String[] args) {

 Scanner sc=new Scanner(System.in);

 System.out.println("Enter cap of Bucket=");

 int n=sc.nextInt();

 System.out.println("Enter cap of Mug=");

 int y=sc.nextInt();

 int count=0;

 int bucket=0;

 while(bucket<n*0.8) {

  System.out.println("Enter amount of water in MUG");

  int x=sc.nextInt();

  if(x<=y) {

   count++;

   bucket+=x;

   

  }

 

 }

 System.out.println("bucket full!");

 System.out.println("no.of mugs:"+count);

 

}

}

Explanation:

Output:

Enter cap of Bucket=

100

Enter cap of Mug=

20

Enter amount of water in MUG

20

Enter amount of water in MUG

20

Enter amount of water in MUG

20

Enter amount of water in MUG

20

bucket full!

no.of mugs:4

80

Similar questions