Taru exam is on the head. So she started learning physics. There she learned about Pascal's law. Now she wanted to try an experiment to get a better understanding of the same.
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.
You have to return the number of buckets that are filled after performing M queries.
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
/*
Taru exam is on the head. So she started learning physics. There she learned about Pascal's law.
Now she wanted to try an experiment to get a better understanding of the same.
All 1
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: Empty all even valued buckets (2, 4, 6 (N).
Query 3: Empty all odd number buckets (1, 3, 5,
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.
*/
int main()
{
int N = 10; //No. of Buckets
int Flag=1;
while(Flag)
{
printf("\n\nPress-1 for Query 1: Fill all the buckets with water.");
printf("\nPress-2 for Query 2: Empty all even valued buckets (2, 4, 6 (N)");
printf("\nPress-3 for Query 3: Empty all odd number buckets (1, 3, 5,--)");
printf("\nPress-4 for Query 4: Empty all the buckets. (1,2,3...N)");
printf("\nPress-0 to QUIT");
printf("\n\tEnter Option (0 to 4): "); scanf("%d",&Flag);
if(Flag==1)
printf("\nNo. of buckets filled = %d",N);
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);
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);
if(Flag==4)
printf("\nNo. of buckets filled = 0");
}
}
Comments
Leave a comment