Concept explainers
a. How do you generate a random integer i such that
b. How do you generate a random integer i such that
c. How do you generate a random integer i such that
d. Write an expression that returns 0 as 1 randomly.
e. Find out what
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Introduction to Programming with C++
Additional Engineering Textbook Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with Python (4th Edition)
Computer Science: An Overview (12th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Problem Solving with C++ (10th Edition)
Starting out with Visual C# (4th Edition)
- write legibly.arrow_forwardAnalyze the following code and fill in the output. I got the answers wrongarrow_forwardWhat does the function return for any positive values of x and n ? The answer should be a general formula in terms of x and n. int what_do_I_do ( int x, int n ) { if ( n = = 1 ) return x; else return x + what_do_I_do ( x, n – 1 ); } C++ be quick pleasearrow_forward
- Write a program that prompts the user to enter an integer from 1 to 7 and displays a pyramid, as presented in the following sample run ---arrow_forwardSuppose you want to deposit a certain amount of money into a savings account and then leave it alone to draw interest for the next 10 years. At the end of 10 years you would like to have $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 thepresent-value formula, to find out: P =F/(1 + r)nThe terms in the formula are as follows:• 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 as arguments. It should return the present value, which is the amount that you need to deposit today. Demonstrate the…arrow_forwardThe following code examines two variables -- x and y -- and prints the largest odd number among them. If none of them is odd, it prints a message to that effect. def largestOdd(x,y): """ x and y are numbers Returns the maximum odd number of x and y. If they all are even, return None """ foundOdd = False largest = 0 if x % 2 == 1 : largest = x foundOdd = True if y % 2 == 1 : if not foundOdd : largest = y foundOdd = True elif y > largest : largest = y if foundOdd : return largest else : return None Assume that largestOdd is called with numbers as arguments.Which of the following test suites would make a path-complete glass box test suite for largestOdd? Question 6 options: Test Suite A: foundOdd(2,4), foundOdd(2,5), foundOdd(11,12), foundOdd(11,13), foundOdd(11,7) Test Suite B: foundOdd(2,4), foundOdd(2,6), foundOdd(11,12),…arrow_forward
- What is the output of the following code ? x = 0 if x < 4 : x = x + 1 print ("x is " , x )arrow_forwardWrite a program using function to check if the number is even or odd?Write a program to return the product of digits of given number.Write a program to find the sum of given 2 numbers.Write a program to find the max of two given numbers.arrow_forwardWhat is the final value of x when the following code is run? int x;for(x =1; x<20; x+=2) {}arrow_forward
- What will be the output of the given code . Do not run the code, i want handwritten solution.arrow_forwardThe interest paid on a savings account is compounded daily. This means that if you start with startbal dollars in the bank, at the end of the first day you’ll have a balance ofstartbal * (1 + rate/365)dollars, where rate is the annual interest rate (0.10 if the annual rate is 10 percent). At the end of the second day, you’ll havestartbal * (1 + rate/365) * (1 + rate/365)dollars, and at the end of n days you’ll havestartbal * (1 + rate/365)ndollars. Write a program that processes a set of data records, each of which contains values for rate, startbal, and n and computes the final account balance.arrow_forwardHow do I write my computer program that shows the current population at 78,000. And there are 365 days in a year. A baby born every 7 seconds, someone dies every 13 seconds and an one new immigrant every 45 seconds. Print the next 5 years populationarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning