/*
Given an array container and integer hunt.
\WAP to find whether hunt is present in container or not.
If present, then triple the value of hunt and search again.
Repeat these steps until hunt is not found. Finally return the value of hunt.
Input: container = {1, 2, 3} and hunt = 1 then Output: 9
Explanation: Start with hunt = 1. Since it is present in array, it becomes 3. Now 3 is present in array and hence hunt becomes 9. Since 9 is a not present, program return 9.
*/
main(void)
{
int Container[] = {1, 2, 3};
int hunt = 2,i,j,l,n, Flag=1;
l = sizeof(Container)/sizeof(Container[0]);
printf("\nInitial Hunt Value = %d",hunt);
while(Flag==1)
{
Flag=0;
for(i=0;i<l;i++)
{
if(hunt==Container[i])
{
Flag=1;
hunt = hunt*3;
}
}
}
printf("\nFinal Hunt Value = %d",hunt);
}
Comments
Leave a comment