Math & Numbers
24 questions · Fundamental Engineering
From the answer group below, select the correct combination of answers to be inserted into A through C in the description.
Function f receives an integer value as argument argval and returns the grade character. The return value of f(, f(, and f( are “A,” “B,” and “C,” respectively. Note that the function has a specification bug.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A through C in the program.
The function isHarshad checks whether the given integer n is a Harshad number. The function returns true if the given number is a Harshad number, or false otherwise. A Harshad number, also known as a Niven number, is a positive integer that is divisible by the sum of its digits. For instance, 156 is a Harshad number because the sum of its digits (1 + 5 + 6 = 12) divides it evenly without a remainder (156 ÷ 12 = 13).
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program.
The quadratic equation a1x2 + b1x + c1 = 0 can be formulated as x2 − 2(−b1/2a1) + (c1/a1) = 0 , where a1 ≠ 0 . If we replace (−b1/2a1) and (c1/a1) by b and c respectively, it can be further formulated as x2 − 2bx + c = 0, and the roots are as follows:
Case 1: if b2 − c = 0, double root b,
Case 2: if b2 − c > 0, two real roots b ± √b2 − c,
Case 3: if b2 − c < 0, two imaginary roots b ± i√c − b2, where i = √−1.
The procedure quadEquation takes the coefficients of a quadratic equation in arguments a1, b1, and c1 and uses the above formula to determine and output the roots. Here, a1 is not 0 and function sqrt returns the principal square root of its non-negative argument.
Answer group
From the answer group below, select the correct answer to be inserted into blank in the program. The same answer goes into both blanks blank. Here, the array index starts at 1.
The program converts the code point of a Unicode character to a 2-byte UTF-8 encoding. In this question, “(16)” after a numerical value indicates a hexadecimal value. Each Unicode character is given an integer value that is known as a code point. A character with a code point that ranges from 80(16) to 7FF(16) is encoded to a 2-byte value as below.
Let the bit pattern with a 2-byte length be: 110xxxxx 10xxxxxx. The underlined 11 “x” positions in the bit pattern store the 11-bit code point. The code point is justified to the right, and 0 is stored in any leftover “x” positions. This 2-byte value is the encoded result. For instance, when the code point AE(16) for Registered Sign character “®” is represented in binary, it is 10101110. When this is stored right-justified in the “x” positions in the bit pattern above, it is 110xxx10 10101110. When 0 is stored in the three leftover “x” positions, the UTF-8 encoding for Registered Sign character “®” 11000010 10101110 is obtained. In decimal form, this corresponds to {194, 174}.
The function encode converts a Unicode code point that is passed as an argument to UTF-8 encoding, and returns an integer array that stores it one byte per element from the start of the array. It is assumed that only an integer value that ranges from 80(16) to 7FF(16) is passed to encode as an argument.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A through C in the program.
The procedure reverse_digits receives one positive integer argument named num and outputs both the original integer and the integer with its digits reversed. Assume that the ones digit of num is not 0.
Example:Number is 456, output 654Number is 23407, output 70432
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program.
Prime numbers are the positive integers that are only divisible by the number itself and 1. Procedure printPrime receives the integer N (N ≥ 1) as an argument and prints the first N prime numbers. For example, printPrime( will print “2 3 5 7 11 13”.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A through C in the program.
Centurial years refer to the years that are divisible by 100. The centurial years are not leap years except for years that are exactly divisible by 400. The non-centurial years, that is, years that are not divisible by 100, refer to leap years that are divisible by 4. The function isLeapYear receives an integer number year and returns true if a given year is a leap year or false otherwise.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program.
The function isPerfect receives positive number n, and returns whether n is a perfect number. Here, a number is a “perfect number” if the sum of its positive divisors (excluding the number itself) is equal to the number itself. For instance, 28 is a perfect number because 28 has divisors 1, 2, 4, 7, and 14, and 1 + 2 + 4 + 7 + 14 = 28.
Answer group
From the answer group below, select the correct answer to be inserted into blank in the description.
The greatest common divisor (GCD) of two numbers is the largest number that divides both of them. The function GCD receives two positive integer numbers and returns their GCD. When the function GCD is called as GCD(, the output is blank in (1)-(4) below. Here, the output statement “output m, n” outputs the values of variables m and n, and subsequently starts a new line.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program.
The following function receives an integer number and returns the result of interpreting the decimal representation of the number as a binary number. Note that the number is non-negative, and its decimal representation comprises only the digits 0 and 1. For instance, if it receives 1100, it returns 12.
Answer group
From the answer group below, select the correct answer to be inserted into blank in the program.
The function calc receives the positive real numbers x and y, and returns the result of the calculation of (√x + √y)2. For instance, when the function calc is called as calc(, the return value is 25. Here, the function pow( returns a raised to the power of b.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program.
Gray code is a sequence of binary numbers in which two successive values differ by only 1 bit. The function GrayBiCon converts the gray code to a binary code using bitwise operators. The bitwise operators operate on the individual bits of the variables. The function receives the 8-bit type argument x as a gray code, and returns a corresponding binary number of the given argument. The value of each bit after conversion is the exclusive OR of the most significant bit in the gray code up to the corresponding bit position and the converted value of the next higher bit position. For instance, when the function GrayBiCon is called as GrayBiCon(, the return value is a binary number 00001000. The common bitwise operators are listed in the table below:
Table Operators
For instance, v << n performs a logical shift of the value of v by n bits to the left.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program.
The function cosine( returns an approximate value of the cosine value of z degrees. The function uses Maclaurin series expansion for the cosine shown below and can be used to determine cos(y) for values of y radians.
cos(y) = 1 − y22! + y44! − y66! + ⋯
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program.
The function coupon receives the argument prod_id (a positive integer value) of product ID, and pur_prod (a positive integer value) of the number of purchased products by a customer. The function returns the number of coupons.
For every purchase of three products of the product ID of which the last digit is three, the customer receives one coupon. Otherwise, they receive no coupon.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program.
The procedure primeFactors outputs the prime factors for the input values as its argument. The first few prime numbers are 2, 3, 5, 7, 11, and 13. For instance, if the input integer is 12, the output is “2×2×3”. If the input integer is 78, the output is “2×3×13”. The input integer must be greater than 1.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A through C in the program.
The standard form of a quadratic equation is as follows:
ax2 + bx + c = 0, where a, b and c are real numbers and a ≠ 0.
Here, the term b2 - 4ac is known as the discriminant of a quadratic equation. It indicates the nature of the roots. The formula for solving a quadratic equation is shown in the figure. If the discriminant value is positive, there are two solutions; if it is zero, there is one solution. Here, we assume that the discriminant value is non-negative.
Figure The formula for solving a quadratic equation
The procedure findRoots receives three real number arguments a, b, and c as coefficients and outputs the value of the root(s) of the quadratic equation. Function sqrt( returns the principal square root value of the parameter discriminant.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A through C in the program.
A school determines the letter grade that a student will receive based on the score, which is an integer value between 0 and 100, as follows:
The function grade receives a score (non-negative integer value between 0 and 100) and returns the letter grade as a character.
Answer group
From the answer group below, select the correct answer to be inserted into blank in the program.
A bus company operates buses between two cities. The standard ticket price is 20 US dollars and the discount ticket price for passenger aged 10 and under or aged 60 and over is 10 US dollars. Additionally, registered members of all ages always get the ticket at the discount price.
The function ticketPrice receives the arguments age (a non-negative integer value) and isMember (a boolean indicating that the passenger is a member if the value is true), which returns the value ret as the ticket price (in US dollars).
Answer group
From the answer group below, select the correct answer to be inserted into blank in the program.
The program outputs the even numbers between 1 and 100. Subsequently, it prints the sum of those even numbers. Note that division is performed for data type integer, that is, a ÷ b is the quotient of a divided by b.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program.
The function sumDigits receives a non-negative integer value num as argument, and returns the sum of the digits of num.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program.
The function division receives two integer values a and b and returns the quotient of a divided by b. The function modulus receives two integer values a and b and returns the remainder of a divided by b. The procedure convert receives the value of seconds as the input argument and outputs that value in the form of hours, minutes, and seconds. For example, when the procedure convert is called as convert( the output is “1, 30, 50”. Here, suppose that the range of input values satisfy 0 ≤ input < 86400.
Answer group
From the answer group below, select the correct answer to be inserted into blank in the program.
The function count1 receives the bit8 type (8-bit type) argument byte, and returns the number of bits 1 in the argument. For example, when the function count1 is called as count1(, the return value is 5.
Here, operator & represents a bitwise logical product, operator | represents a bitwise logical sum; operator >> represents a logical shift to the right, and operator << represents a logical shift to the left. For example, v << n performs a logical shift of the value of v by n bits to the left.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program.
The Fibonacci sequence is a sequence in which each number is equal to the sum of the two preceding numbers. In this question, the sequence starts with 0 and 1. The first 10 values in the sequence are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34. For example, the 8-th number 13 is the sum of the two preceding numbers 5 and 8.
The function fibo takes an integer value n as the argument and returns the value at the n-th position. Here, n reflects the position of the number in the sequence, starting with 1 (one). When n is 9, the function returns 21.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program.
The function m_sin calculates and returns the approximate value of sin(x) for the argument x using the Maclaurin expansion. The program calculates sin(x) using the approximate formula below:
sin(x) = x/1! - x3/3! + x5/5! - … + (-1)n × ( x(2n+1)/(2n+1)!)
Here, ! is the factorial symbol, and n is the first integer for which | x(2n+1) / (2n+1)! | ≤ 10-7 is satisfied.
Answer group