Concept explainers
The Fibonacci numbers
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Absolute Java (6th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Introduction To Programming Using Visual Basic (11th Edition)
C Programming Language
- When you borrow money to buy a house, a car, or for some other purpose, you repay the loan by making periodic payments over a certain period of time. Of course, the lending company will charge interest on the loan. Every periodic payment consists of the interest on the loan and the payment toward the principal amount. To be specific, suppose that you borrow $1,000 at an interest rate of 7.2% per year and the payments are monthly. Suppose that your monthly payment is $25. Now, the interest is 7.2% per year and the payments are monthly, so the interest rate per month is 7.2/12 = 0.6%. The first months interest on $1,000 is 1000 0.006 = 6. Because the payment is $25 and the interest for the first month is $6, the payment toward the principal amount is 25 6 = 19. This means after making the first payment, the loan amount is 1,000 19 = 981. For the second payment, the interest is calculated on $981. So the interest for the second month is 981 0.006 = 5.886, that is, approximately $5.89. This implies that the payment toward the principal is 25 5.89 = 19.11 and the remaining balance after the second payment is 981 19.11 = 961.89. This process is repeated until the loan is paid. Write a program that accepts as input the loan amount, the interest rate per year, and the monthly payment. (Enter the interest rate as a percentage. For example, if the interest rate is 7.2% per year, then enter 7.2.) The program then outputs the number of months it would take to repay the loan. (Note that if the monthly payment is less than the first months interest, then after each payment, the loan amount will increase. In this case, the program must warn the borrower that the monthly payment is too low, and with this monthly payment, the loan amount could not be repaid.)arrow_forward.arrow_forwardA number of the form a + ib, in which i2 = -1 and a and b are real numbers, is called a complex number. We call the real part and b the imaginary part of a + ib. Complex numbers can also be represented as ordered pairs (a, b). The addition and multiplication of complex numbers are defined by the following rules: (a + ib) + (c + id) = (a + c) + i(b + d ) (a + ib) * (c + id) = (ac - bd) + i(ad + bc) Using the ordered pair notation, these rules are written as: (a, b) + (c, d) = ((a + c), (b + d )) (a, b) * (c, d) = ((ac - bd ), (ad + bc)) C++ has no built-in data type that allows us to manipulate complex numbers. Construct a data type, complex Type, that can be used to process complex numbers. Overload the stream insertion and stream extraction operators for easy input and output. We will also overload the operators + and * to perform addition and multiplication of complex numbers. If x and y are complex numbers, we can evaluate expressions such as x + y and x * y.arrow_forward
- Please answer it in Python Suppose we play a game where each round takes place in the following way: first, we roll a dice, and its result gives the number of points at stake. Then, the player can, if he wishes, trigger his bonus "double account" or his bonus "triple account". Then, the player answers a number of questions, and calculates his percentage of correct answers. The points awarded to the player for that round are then calculated based on the percentage of correct answers and the number of points in play rounded to the nearest integer (for example, with 50% correct answers and 6 points in play, the player gets 3 points; with 45% correct answers and 8 points in play, the player gets 4 points). Finally, this number of points is possibly multiplied by two or three if the corresponding bonus has been used. Write a function points_match that takes as an argument the percentage, the number of points at stake, and as an optional argument the multiplier (which is worth 2 in a double…arrow_forwardA year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: The year must be divisible by 4 If the year is a century year (1700, 1800, etc.), the year must be evenly divisible by 400 Some example leap years are 1600, 1712, and 2016. Write a program that takes in a year and determines whether that year is a leap year. Ex: If the input is 1712, the output is: 1712 is a leap year. Ex: If the input is 1913, the output is: 1913 is not a leap year. 1 2 3 4 5 6 7 8 9 10 11 Put("{} is a leap year.".format(i_year)) print("{} is not a leap year.".format(i_year)) inputYear = Get next input What would be the code?arrow_forwardA decreasing sequence of numbers is a sequence of integers where every integer in the sequence is smaller than all other previous integers in that sequence. For example, •35, 16, 7, 2, 0, -3, -9 is a decreasing sequence of numbers. The length of this sequence is 7 (total numbers in the sequence) and the difference of this sequence is 35 - (-9) -44. • 5 is a decreasing sequence of numbers with length 1 and difference 5-5 = 0 •99,-99 is a decreasing sequence of numbers with length 2 and difference 99-(-99) = 198 •17, 23, 11, 8, -5, -3 is not a decreasing sequence of %3D numbers. Write a program that contains a main() function. The main function repeatedly asks the user to enter an integer if the previously entered integers form a decreasing sequence of numbers. This process stops as soon as the latest user input breaks the decreasing sequence. Then your function should print the length and difference of the decreasing sequence. Finally, call the main() function such that the call will be…arrow_forward
- hexadecimal We usually write numbers in decimal form (or base 10), meaning numbers are composed using 10 different “digits” {0, 1, . . . , 9}. Sometimes though it is useful to write numbers hexadecimal or base 16. Now there are 16 distinct digits that can be used to form numbers: {0,1,...,9,A,B,C,D,E,F}. So for example, a 3 digit hexadecimal number might be 2B8. (d) How many 3-digit hexadecimals start with a letter (A-F) or end with a numeral (0-9) (or both)? Explain (please answer it the way i can make myself understand)arrow_forwardProgramming Exercise 10 in Chapter 6 asks you find the mean and standard deviation of five numbers. Extend this programming exercise to find the mean and standard deviation of up to 100 numbers. Suppose that the mean (average) of n numbers x1, x2, . . ., xn is x. Then the standard deviation of these numbers is:S=sqrt(((x1-x)^2+(x2-x)^2+...+(xi-x)^2+...+(xn-x)^2)/n)arrow_forwardnbm.m//,//arrow_forward
- In mathematics, a prime number is a natural number greater than 1 that is not a product of two smaller natural numbers, i.e. is it has only two factors 1 and itself. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 x 1, involve 5 itself. Note that the prime number series is: 2, 3, 4, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, .. a. Write a Java method named isPrime that takes a natural number as a parameter and returns the if the given number is prime or not using the following header: Public static boolean isPrime (int num) b. Write a Java class called PrimeNumbers that: Reads from the user a natural value n (should be less than or equal 200). Prints a list of the prime numbers from 2 to n and their number and values. The program has to work EXACTLY as given in the following sample run. Hints: You should create a single dimension array to store the prime…arrow_forwardWhen you use a mortgage to purchase a home, the lending institution effectively owns the home. You buy back part ownership in the home with each monthly payment. The part you have bought back is your equity in the home. If the mortgage amount is P dollars, the monthly interest rate is r as a decimal, and the term of the mortgage is t months, then your equity after k payments is E(k) = P((1 + r)k − 1) (1 + r)t − 1 dollars. In this exercise, assume that the mortgage amount is $200,000, the APR is 6% so r = .06/12 and the term of the loan is 30 years (360 months). (a) Find a formula for the equity. (b) Make a graph of the equity over 360 months, the term of the loan. (c) Does the graph show that you have half-ownership in the home halfway through the term of the mortgage? Halfway through the term of the mortgage corresponds to k1 = _______ payments. From the graph, we see that E(k1) is ________ half of the mortgage amount, so we _______ have half-ownership in the home…arrow_forwardSuppose you have a certain amount of money in a savings account that earns compoundmonthly interest, and you want to calculate the amount that you will have after a specificnumber of months. The formula is as follows: F=P×(1+i)tF=P×(1+i)t The terms in the formula are: • F is the future value of the account after the specified time period.• P is the present value of the account.• i is the monthly interest rate.• t is the number of months.• F is the future value of the account after the specified time period.• P is the present value of the account.• i is the monthly interest rate.• t is the number of months. $$ Write a program that prompts the user to enter the account’s present value, monthly interest rate, and the number of months that the money will be left in the account. The program should pass these values to a function that returns the future value of the account, after the specified number of months. The program should display the account’s future value.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr