Answer to Question #255056 in C for xyz

Question #255056
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.
1
Expert's answer
2021-10-22T02:05:43-0400
/*
	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);
		
}

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
APPROVED BY CLIENTS