Concept explainers
If originally
Trending nowThis is a popular solution!
Chapter 5 Solutions
Computer Science: A Structured Programming Approach Using C, Third Edition
- The following statement should determine if x is not greater than 20. What is wrong with it?arrow_forwardWrite code that iterates while userNum is less than 12. Each iteration: Put userNum to output. Then, put "/" to output. Then, assign userNum with userNum multiplied by 3.arrow_forwardWhat is the output of the following code? a = 200 b = 33 c = 500 if a > b and c> a: print(a+c) else: print(a)arrow_forward
- -scripting language Write a program that randomly generates a lottery between 100 and 999 (random.randint(100, 999)), prompts the user to enter a number in the same range, and determines whether the user wins according to the following rule: (1) If the user input matches the lottery in exact order, print "the award is $10,000". E.g., lottery = 123, input = 123(2) If the user input matches the lottery, but in wrong order, print "the award is $6,000". E.g., lottery = 123, input = 321(3) If two digits in the user input matches a digit in the lottery, print "the award is $3,000". E.g., lottery = 123, input = 612(4) If one digit in the user input matches a digit in the lottery, print "the award is $1,000". E.g., lottery = 123, input = 289(5) If none of the digits is matched, print "thank you".arrow_forwardExercise III: Catalan numbers For n e N, denote by c, to be the number of ways to form a "mountain range" with n upstrokes (U) and n downstrokes (D) that all stay above a horizontal line. For instance: for n = 1, only UD is allowed, so c = 1; • for n = 2, only UUDD and UDUD are allowed, so c2 = 2. 1. Check that c3 = 5 by writing down or drawing all possible options. 2. Consider the power series +00 g(x) = 2 n=0 (by definition co = 1) called the generating function of the sequence (en). Justify that cn < 4" for each n, and deduce that the radius of convergence of g is at least 1/4. 3. It can be show that for r E (-1/4, 1/4), g(x) = 1+ xg(r)? and therefore 1- VI 4.x g(x) = 2.x Use this formula and the known power series of V1+ x to write the first terms of the power series expansion of g, in the form g(x) = co + c1x + c2x2 + C3x + c4x* + ·.. Show how you obtain a few terms, but you do not need to show all computations and you can use a calculator for fractions. Check that you recover co,…arrow_forwardUsing C++, code the following problem: A friend of yours is on the cheer squad for their football team. Each time the team scores, the cheer squad does pushups — one for each point the team has scored so far. If the teams scores a touchdown (7 points), the squad does 7 pushups. If the team then scores a field goal (3 points), the cheer squad does 10 pushups. If the team then scores a safety (2 points), the squad will do 12 pushups. At the end of that game, the squad will end up having done 7+10+12=29 pushups! You meet your friend after a game, and they say “Boy, am I tired! I did a total of n pushups at the game today!” and promptly collapse from exhaustion. Given n, the number of pushups, can you figure out how the team scored? More than one score may be possible. For example, for 29 pushups, the team could have scored 3, then 2, then 2, then 7, for a total of 14 points. If so, find the highest possible score. Input Format There are multiple test cases. Each test case will…arrow_forward
- Assuming the code x = 3 - 6 + 5 - 5 * (++x) ; has been executed correctly, what is the value of integer x?arrow_forwardThe following PThreads code is written for book reservation in a library. Each student checks if the book is free. If it was free they will reserve it with their own ID and the book becomes unavailable to the rest. a. Can you identify the problem with this code? Explain the condition that the code may fail. b. Rewrite the code (just a few lines of code) to solve the problem. //PThreads code here if (book.state==free) ( book.state%-reserved; book.borrower%=MyID;arrow_forwardSuppose you want to deposit a certain amount of money into a savings account, and thenleave it alone to draw interest for the next 10 years. At the end of 10 years, you would like tohave $10,000 in the account. How much do you need to deposit today to make that happen?You can use the following formula, which is known as the present value formula, to find out:The terms in the formula are as follows: [5 marks]• P is the present value, or the amount that you need to deposit today.• F is the future value that you want in the account. (In this case, F is $10,000.)• r is the annual interest rate.• n is the number of years that you plan to let the money sit in the account.Write a method named presentValue that performs this calculation. The method should accept the future value, annual interest rate, and number of years asarguments. It should return the present value, which is the amount that you need to deposit today.Demonstrate the method in a program that lets the user experiment with…arrow_forward
- What is the result of the following code? x = 10 y = 15 print(x = y)arrow_forwardWrite a flowchart and pseudocode like this: Pseudocode: Start inputmyNumber Set myAnswer-myNumber * 10 output myAnswer 1.The Dash Cell Phone Company charges customers a basic rate of $5 per month to send text messages. Additional rates are as follows: The first 100 messages per month, regardless of message length, are included in the basic bill. An additional three cents are charged for each text message after the 100th message, up to and including 300 messages. An additional two cents are charged for each text message after the 300th message. Federal, state, and local taxes add a total of 14 percent to each bill. THANKYOUUarrow_forwardWhat is the final value of x when the following code is run? int x;for(x =1; x<20; x+=2) {}arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,