Question
C programming if you would kindly You need to submit the second code with Guessing Game based on Ternary Search. Ternary Search presupposes that during
C programming if you would kindly
You need to submit the second code with Guessing Game based on Ternary Search.
Ternary Search presupposes that during the game the search space is reduced by 2/3 rather than cut by half. For example, let us suppose that low=0 and high is 90. We define two markers whose values would be
m1=30
m2=60
We will ask to press a certain key if
target number is equal to m1 or m2
target number is greater than m2
target number smaller than m2
New search space would contain only 30 numbers. Continue accordingly.
APPENDIX 1
#include "pch.h"
#include
int main()
{
int high, low, middle;
char input;
printf("Please enter low bound ");
scanf_s("%d", &low);
printf("Please enter high bound ");
scanf_s("%d", &high);
printf("Your number has to be between %d and %d ", low, high);
while (low <= high)
{
middle = ?;
printf(" Please, press E or e if your number is equal to %d ", middle);
printf(" Please, press G or g if your number is greater than %d ", middle);
printf(" Please, press S or s if your number is smaller than %d ", middle);
scanf_s(" %c", &input);
if (input == 'E' || input == 'e')
{
printf("Done! I've guessed your number ");
low = ?; // MAKE LOOP CONDITION FALSE
}
else
{
if (input == 'G' || input == 'g')
low = ?;
else
high = ?;
}
}
printf(" Thanks for playing! ");
}
APPENDIX 2
Please enter low bound
20
Please enter high bound
180
Your number has to be between 20 and 180
I will guess your number m aximum with 8 questions
Question 1
Please, press E or e if your number is equal to 100
Please, press G or g if your number is greater than 100
Please, press S or s if your number is smaller than 100
g
Question 2
Please, press E or e if your number is equal to 140
Please, press G or g if your number is greater than 140
Please, press S or s if your number is smaller than 140
s
Question 3
Please, press E or e if your number is equal to 120
Please, press G or g if your number is greater than 120
Please, press S or s if your number is smaller than 120
e
Done! I've guessed your number with 3 questions
Thanks for playing!
here's what I have for a binomial function for a guessing game in the C language.
#include
int main() { int min; int max; int middle; char input;
printf("Please enter a minimum number: ");
scanf("%d", &min);
printf("Please enter a maximum number: ");
scanf("%d", &max);
printf("You minimum values is %d, and you maximum value is %d : ", min, max); /* * find how many questions you need to ask * print: the program is going to guess your number */
while (min<=max) { middle = (min + max) / 2;
printf("Please enter E if the number is equal to %d ", middle); printf("Please enter L if the number is larger to %d ", middle); printf("Please enter S if the number is smaller to %d ", middle);
scanf("%c", &input);
if (input == 'E') { printf("The program has guessed your number "); /*let's break out of this!*/ min = max + 1; } else { if (input == 'L') min = middle + 1;
else max = middle - 1; } if (input != 'E') { printf("OK this program has ran every single number you picked... you are a dirty cheater. ")
} } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started