Answer to Question #300294 in C++ for taru

Question #300294

 For the experiment Taru has N buckets (numbered from 1,2,3..N) which all are initially empty. She has M number of queries. Each query represents an integer that is of 4 types. Query 1: Fill all the buckets with water •Query 2: Empre even valued buckets (2, 4, 6 N) Query 3: Empty all odd number buckets (1, 3, 5, N). •Query 4: Empty all the buckets (1,2,3. N). You have to return the number of buckets that are filled after performing M queries,using fillbucket function


1
Expert's answer
2022-02-21T01:27:47-0500
#include <stdio.h>
#include <stdlib.h>

int main() {
  int n = 10;
  int flag = 1;
  while (flag) {
    printf("\n\nPress-1 for Queue 1: Fill all the buckets with water.");
    printf("\nPress-2 for Queue 2: Empty all even valued buckets (2, 4, 6, (N))");
    printf("\nPress-3 for Queue 3: Empty all odd number buckets (1, 3, 5, (N-1))");
    printf("\nPress-4 for Queue 4: Empty all the buckets. (1, 2, 3 ... N");
    printf("\nPress-0 for QUIT");
    printf("\n\tEnter Option (0 to 4): ");
    scanf("%d", &flag);
    if (flag == 1) {
      printf("\nNo. of buckets filled = %d", n);
    } else if (flag == 2) {
      if (n % 2 == 0) {
        printf("\nNo. of buckets filled = %d", n / 2);
      } else {
        printf("\nNo. of buckets filled = %d", (n + 1) / 2);
      }
    } else if (flag == 3) {
      if (n % 2 == 0) {
        printf("\nNo. of buckets filled = %d", n / 2);  
      } else {
        printf("\nNo. of buckets filled = %d", (n + 1) / 2);
      }
    } else if (flag == 4) {
      printf("\nNo. of buckets filled = 0");
    }
  }
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog