(Fibonacci) The Fibonacci series
0, 1, 1, 2, 3, 5, 8, 13, 21, …
begins with the terms 0 and 1 and has the property that each succeeding term is the sum of the two preceding terms. a) Write a nonrecursive function fibonacci(n) that calculates the nth Fibonacci number. Use unsigned int for the function’s parameter and unsigned long long int for its return type. b) Determine the largest Fibonacci number that can be printed on your system.
Learn your wayIncludes step-by-step video
Chapter 5 Solutions
MYPROGRAMMINGLAB WITH PEARSON ETEXT
Additional Engineering Textbook Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Absolute Java (6th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Programming in C
C Programming Language
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- 4. (Prime Numbers) An integer is said to be prime if it is divisible by only 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. Write a function called isPrime that receives an integer and determines whether the integer is prime or not. Write a test program that uses isPrime to determine and prints all the prime numbers between 1 and 1000. Display 10 numbers per line.arrow_forward(Statics) An annulus is a cylindrical rod with a hollow center, as shown in Figure 6.7. Its second moment of inertia is given by this formula: I4(r24r14) I is the second moment of inertia (m4). r2 is the outer radius (m). r1 is the inner radius (m). a. Using this formula, write a function called annulusMoment ( ) that accepts two double-precision numbers as parameters (one for the outer radius and one for the inner radius), calculates the corresponding second moment of inertia, and displays the result. b. Include the function written in Exercise 5a in a working program. Make sure your function is called from main(). Test the function by passing various data to it.arrow_forward(Statics) A beam’s second moment of inertia, also known as its area moment of inertia, is used to determine its resistance to bending and deflection. For a rectangular beam (see Figure 6.6), the second moment of inertia is given by this formula: Ibh3/12 I is the second moment of inertia (m4). b is the base (m). h is the height (m). a. Using this formula, write a function called beamMoment() that accepts two double- precision numbers as parameters (one for the base and one for the height), calculates the corresponding second moment of inertia, and displays the result. b. Include the function written in Exercise 4a in a working program. Make sure your function is called from main(). Test the function by passing various data to it.arrow_forward
- (Numerical) Heron’s formula for the area, A, of a triangle with sides of length a, b, and c is A=s(sa)(sb)(sc) where s=(a+b+c)2 Write, test, and execute a function that accepts the values of a, b, and c as parameters from a calling function, and then calculates the values of sand[s(sa)(sb)(sc)]. If this quantity is positive, the function calculates A. If the quantity is negative, a, b, and c do not form a triangle, and the function should set A=1. The value of A should be returned by the function.arrow_forward(Algebra: solve 2 X 2 linear equations) You can use Cramer's rule to solve the following 2 x 2 system of linear equations: ed – bf af – ec y bc ax + by = e X = cx + dy = f ad ad – bc Write a function with the following header: void solveEquation(double a, double b, double c, double d, double e, double f, double& x, double& y, bool& isSolvable) If ad – bc is 0, the equation has no solution and isSolvable should be false. Write a program that prompts the user to enter a, b, c, d, e, and f and displays the result. If ad – bc is 0, report that "The equation has no solution." See Program- ming Exercise 3.3 for sample runs.arrow_forwardDo fast i will give u like for surearrow_forward
- (python) Speed of Sound is a constant 343 m/s Create a function that will return the Frequency Heard based on the above equation. The function should accept the following parameters: speed of sound, velocity of receiver, velocity of source and frequency of source. Make sure to prompt the user for the input data and call the function. Example Values/Results: Frequency of Source: 935 HzVelocity of receiver: 24 m/sVelocity of source 43 m/sHeard frequency is 888.977 Hzarrow_forward(2) The ceiling of a floating-point number x is the smallest integer that is still larger than or equal to x. Alternatively, the ceiling of a floating-point number x is what you get when you round x up to the nearest integer. For example, the ceiling of 2.1 is 3, the ceiling of 0.9 is 1, the ceiling of -4.5 is -4, etc. Write a function called ceiling (number) to compute the ceiling of a floating-point number (input argument) and returns one integer value. You may not use python's ceil() or floor() functions. Your function may use int() and/or float() functions, and your solution must use the floor division operator (i.e., '//").arrow_forward(a) Write the following functions and their docstrings: • between (num1, num2, num3) takes 3 integer arguments and returns True if num2 is between num1 and num3. It is not between them if it is equal to either of the other two. For example, given the inputs 5, 3 and 0, the value returned should be True. Given the inputs -2, 2 and 2, False should be returned. Note that there is no restriction that num1 must be less than num3. • majorityEven (num_list) returns True if more than half of the integers in the num_list are di- visible by 2, with no remainder, otherwise it returns False. The list can be of any size. Recall that zero is divisible by 2 with no remainder. For example, the function should return False for the list [1,2,3,6] (as only two of the four numbers are divisible by 2) and True for the list [0,1,-4] (as two of the three numbers are divisible by 2). (b) Generate at least six test cases for each function you wrote in part (a). You may use white-box and/or black-box test case…arrow_forward
- (C++ language)arrow_forward: Write a function that adds two numbers. You should not use+ or any arithmeticoperators.arrow_forward(Rounding Numbers) Function floor may be used to round a number to a specific decimal place. The statement y = floor(x * 10 + .5) / 10; rounds x to the tenths position (the first position to the right of the decimal point). The statement y = floor(x * 100 + .5) / 100; rounds x to the hundredths position (the second position to the right of the decimal point). Write a program that defines four functions to round a number x in various ways a) roundTolnteger(number) b) roundToTenths(number) c) roundToHundreths(number) d) roundToThousandths(number) For each value %3D read, your program should print the original value, the number rounded to the nearest integer, the number rounded to the nearest tenth, the number rounded to the nearest hun- dredth, and the number rounded to the nearest thousandth. IN C PROGRAMMING LANGUAGE PLEASEarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning