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
#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;
}
Comments
Leave a comment