Question

In: Computer Science

In the following code, what values could be read into a number to terminate the while...

In the following code, what values could be read into a number to terminate the while loop? PRINT "Enter a number: READ user input number ← user input WHILE (number < 1 or number > 10) PRINT "Enter another number: " READ user input number ← user input END WHILE

A) Numbers in the range 0 - 9

B) Numbers in the range 1 - 10

C) Numbers greater than 10

D) Numbers less than 1

Solutions

Expert Solution

Solution:

Option B is correct which is Numbers in range 1-10 (including 1 and 10)

Example code in C:

#include <stdio.h>
int main()
{
   int n,an;
   printf("Enter a number:");
   scanf("%d",&n);
   while(n<1 || n>10)
   {
       printf("enter another number:");
       scanf("%d",&n);
   }
}

In output file first line tried range between 0-9 where loop still runs and next one numbers less than 1 and next one numbers greater than 10 and when I give input range between 1-10 (you can try even other numbers like 2,3,4..) then loop terminated.

Thank you, Have a great day:-)


Related Solutions

The number 986 could have a variety of meanings. They could be used as a code...
The number 986 could have a variety of meanings. They could be used as a code (Dx code 986 in ICD-9-CM), a radio station (98.6 FM) or even a temperature (98.6 Degrees F). The raw numbers 986 equal data that is then transferred into information, which has meaning. Think about and discuss the concepts of data and information. What is the data, information, knowledge continuum? Also, discuss how data supports quality assessment and the importance of data quality for outcome...
[PLEASE USE C++] Write a function to read values of a number of rows, number of...
[PLEASE USE C++] Write a function to read values of a number of rows, number of columns, 2 dimensional (2D) array elements and display the 2D array in a matrix form. Input 2 3 1 4 5 2 3 0 Where, First line of represents the number of rows. Second line of input represents the number of columns. Third line contains array elements of the 1st row and so on. Output 1 4 5 2 3 0 where There must...
Write code in MIPS ,read tow number from the user that do the following: 1- multiply...
Write code in MIPS ,read tow number from the user that do the following: 1- multiply 2- Dividing 3- sum 4- average 5- minimum 6- maximum 7- print message to thank the user for using my program
1. Write a C++ code segment to read 50 temperature values in Fahrenheit and to convert...
1. Write a C++ code segment to read 50 temperature values in Fahrenheit and to convert them to Celsius. You convert a Fahrenheit temperature to Celsius by using the following formula: Celsius = 5.0 / 9 * (Fahrenheit - 32). 2.A client has purchased 20 products in a store. Write a C++ code segment to read the unit price and the number of items of each product and to compute and print the total price of all these products.
Thinking in Assembly language What values will be written to the array when the following code...
Thinking in Assembly language What values will be written to the array when the following code executes? .data array DWORD 4 DUP(0) .code main PROC mov eax,10 mov esi,0 call proc_1 add esi,4 add eax,10 mov array[esi],eax INVOKE ExitProcess,0 main ENDP proc_1 PROC call proc_2 add esi,4 add eax,10 mov array[esi],eax ret proc_1 ENDP proc_2 PROC call proc_3 add esi,4 add eax,10 mov array[esi],eax ret proc_2 ENDP proc_3 PROC mov array[esi],eax ret proc_3 ENDP
What are the values in arrays a, b, and c after the following code executes (list...
What are the values in arrays a, b, and c after the following code executes (list all of the elements of the arrays)? double[] a = new double[4]; double[] b = {6,4,2}; a[a.length-1] = b[b.length-1]; double[] c = b; c[0] = -1; b[1] = c[2]; c = a; c[0] = -2; a[1] = c[3];
I need code for the HCS12 Dragon trainer plus 2 that allows me to read values...
I need code for the HCS12 Dragon trainer plus 2 that allows me to read values from its built in temperature sensor and displays those values on the seven segment displays .
If the United States legislated that all employers could only terminate an employee for “just cause”...
If the United States legislated that all employers could only terminate an employee for “just cause” (and thus eliminating the doctrine of “employment at will”) we would expect (over time), all things being held the same, that: the natural rate of unemployment will rise cyclical unemployment would fall frictional unemployment would fall because companies will want to hire workers quickly structural unemployment would fall because workers will work harder consistent with the efficiency wage hypothesis
2. Translate the following C/Java code to MIPS assembly code. Assume that the values of a,...
2. Translate the following C/Java code to MIPS assembly code. Assume that the values of a, i, and j are in registers $s0, $t0, and $t1, respectively. Assume that register $s2 holds the base address of the array A (add comments to your MIPS code). j = 0; for(i=0 ; i<a ; i++) A[i]=i+j++;
Study the following code with a while-loop and convert it to a for-loop (fill in the...
Study the following code with a while-loop and convert it to a for-loop (fill in the blanks). int i=4, result=1; while(i>1) { result *= i; i--; } The following for-loop performs the same functionality: int result=1; for (__________ i=4; i _________1;____________) { result *= i; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT