Define a function called check_num that… • Has two parameters that are integers,
ID: 3686735 • Letter: D
Question
Define a function called check_num that…
• Has two parameters that are integers, which are not guaranteed to be in any particular order.
• Prompts the user to enter an integer. (You can assume that the user always enters an actual integer.)
• Returns the user’s number only if it is between the values of the parameters, inclusive. That is, if the user’s value is equal to one of the parameters, it will still count as between.
• Otherwise, keeps repeating these steps until the user enters a number that is between the two parameters.
Explanation / Answer
Answer for Question:
This below chec_num function will read the user_input and will check the input
lies between if statement or else statement otherwise will read the number once again
will start check the range.
See the below code:
int chec_num(int param1, int param2)
{
int user_input, lag = 1;
printf("Enter User Input : ");
scanf("%d",&user_input);
while(falg != 0)
{
if(user_input < param1 && param2 > user_input)
{
return user_input;
flag = 0;
}
else if(user_input == param1 || user_input == param2)
{
printf("Still input is between these two numbres ");
return user_input;
flag = 0;
}
else
{
printf("Re- Enter the user Input :");
scanf("%d",&user_input);
flag = 1;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.