C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 4, Problem 4.35E
(Factorial) The factorial of a nonnegative integer n is written n! (pronounced “n factorial”) and is defined as follows:
n! = n.(n-1)·(n-2)·…·1 (for values of n greater than 1)
and
n! = 1 (for n = 0 or n = 1).
For Example. 5! = 5·4·3·2·1, which is 120. Use while statement in each of the following:
- Write a
program that reads a nonnegative integer and computes and prints its factorial. - Write a program that estimates the value of the mathematical constant e by using the formula:
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
telk
(Business: check ISBN-10)
Question 11
An ISBN-10 (International Standard Book Number) consists of 10 digits:
dididadadsded,d dad1o. The last digit, d10, is a checksum, which is čalculated from the other
nine digits using the following formula:
(d, x1+dz x 2 + d, X 3+ d, X'4 + de X5 + de X 6 + d, × 7 + dg × 8+ dy X 9) % 11
If the checksum is 10, the last digit is denoted as X, according to the ISBN convention. Write a
program that prompts the user to enter the first 9 digits as a string and displays the 10-digit
ISBN (Including leading zeros). Your program should read the input-as a string.
Here are sample runs
Enter the first 9 digits of an SBN-10 as a string: 013601267
The ISBN-10 number is: 01360112671
Show transcribed image text
6.Coding-----""Euler's totient function, also known as phi-function ϕ(n),counts the number of integers between 1 and n inclusive,which are coprime to n.(Two numbers are coprime if their greatest common divisor (GCD) equals 1)."""def euler_totient(n): """Euler's totient function or Phi function. Time Complexity: O(sqrt(n)).""" result = n for i in range(2, int(n ** 0.5) + 1): if n % i == 0: while n % i == 0: n //= i.
(Python matplotlib or seaborn)
CPU Usage
We have the hourly average CPU usage for a worker's computer over the course of a week. Each row of data represents a day of the week starting with Monday. Each column of data is an hour in the day starting with 0 being midnight.
Create a chart that shows the CPU usage over the week. You should be able to answer the following questions using the chart:
When does the worker typically take lunch?
Did the worker do work on the weekend?
On which weekday did the worker start working on their computer at the latest hour?
cpu_usage = [
[2, 2, 4, 2, 4, 1, 1, 4, 4, 12, 22, 23,
45, 9, 33, 56, 23, 40, 21, 6, 6, 2, 2, 3], # Monday
[1, 2, 3, 2, 3, 2, 3, 2, 7, 22, 45, 44,
33, 9, 23, 19, 33, 56, 12, 2, 3, 1, 2, 2], # Tuesday
[2, 3, 1, 2, 4, 4, 2, 2, 1, 2, 5, 31,
54, 7, 6, 34, 68, 34, 49, 6, 6, 2, 2, 3], # Wednesday
[1, 2, 3, 2, 4, 1, 2, 4, 1, 17, 24, 18,
41, 3, 44, 42, 12, 36, 41, 2, 2, 4, 2, 4], # Thursday
[4, 1, 2, 2, 3, 2, 5, 1, 2, 12, 33, 27,
43, 8,…
Chapter 4 Solutions
C++ How to Program (10th Edition)
Ch. 4 - (Correct the Code Errors) Identity and correct the...Ch. 4 - (What Does this Program Do?) What does the...Ch. 4 - For Exercises 4.13—4.16, perform each of these...Ch. 4 - For Exercises 4.13—4.16, perform each of these...Ch. 4 - For Exercises 4.13—4.16, perform each of these...Ch. 4 - For Exercises 4.13—4.16, perform each of these...Ch. 4 - (Find the largest) The process of finding the...Ch. 4 - (Tabular Output) Write a C++ program that uses a...Ch. 4 - (Find the Two Largest Numbers) Using an approach...Ch. 4 - (Validating User Input) The examination-results...
Ch. 4 - (What Does this Program Do?) What does the...Ch. 4 - (What Does this Program Do?) What does the...Ch. 4 - (Dangling-else Problem)C++ compliers always...Ch. 4 - (Another Dangling-else Problem) Based on the...Ch. 4 - (Another Dangling-else Problem) Based on the...Ch. 4 - (Square of Asterisks) Write a program that reads...Ch. 4 - (Palindromes) A palindrome is a number or a text...Ch. 4 - (Printing the Decimal Equivalent of a Binary...Ch. 4 - (Checkerboard Pattern of Asterisks) W rite a...Ch. 4 - (Multiples of 2 with an Infinite Loop) write a...Ch. 4 - (Calculating a Circle’s Diameter, circumference...Ch. 4 - What’s wrong with the following statement? Provide...Ch. 4 - (Sides of a Triangle) Write a program that reads...Ch. 4 - (Sides of a Right Triangle) Write a program that...Ch. 4 - (Factorial) The factorial of a nonnegative integer...Ch. 4 - (Modified Account Class) Modify class Account...Ch. 4 - (Enforcing Privacy with Cryptography) The...Ch. 4 - (World Population Growth) World population has...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- The correct statements are: For L = 0, L* = {e} For L = {e}, L* = {e} OL+ = LL* L* = LL+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 equation: ed – bf ax + by = e cx + dy = f af - eс y ad – bc %3D ad – bc 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."arrow_forwardAlert dont submit AI generated answer.arrow_forward
- integer) Write a function that computes the sum of the digits in an integer. Use the following function header:def sumDigits(n):For example, sumDigits(234) returns 9 (Hint: Use the % operator to extract digits, and the // operator to remove the extracted digit. For instance, toextract 4 from 234, use 234 % 10 To remove 4 from 234, use 234 // 10 (=23) Use a loop to repeatedly extract and remove the digits until all the digits are extracted.) Write a test program that prompts the user to enter an integer and displays the sum of all its digits.arrow_forward(Numerical) Using the srand() and rand() C++ library functions, fill an array of 1000 floating-point numbers with random numbers that have been scaled to the range 1 to 100. Then determine and display the number of random numbers having values between 1 and 50 and the number having values greater than 50. What do you expect the output counts to be?arrow_forwardWhen you perform arithmetic operations with operands of different types, such as adding an int and a float, ____________. C# chooses a unifying type for the result you must choose a unifying type for the result you must provide a cast you receive an error messagearrow_forward
- Trigonometry: The basic MATLAB trigonometric functions are sin, cos, tan, cot, sec, and csc. The inverses, e.g., arcsin, arctan, etc., are cal- culated with asin, atan, etc. The same is true for hyperbolic functions. The inverse function at an2 takes two arguments, y and x, and gives the four- quadrant inverse tangent. The argument of these functions must be in radians. Calculate the following quantities: sin, cost, and tan. sin²+ cos². (Typing sin^2(x) for sin²x will produce an error). y cosh²z-sinh² x, with x = 32m.arrow_forward4. Odd-Even-inator by CodeChum Admin My friends are geeking out with this new device I invented. It checks if a number is even or odd! ? Do you want to try it out? Instructions: In the code editor, you are provided with a function that checks whether a number is even or odd. Your task is to ask the user for the number of integer, n, they want to input and then the actual n number values. For each of the number, check whether it is even or odd using the function provided for you. Make sure to print the correct, required message. Input 1. Integer n 2. N integer valuesarrow_forwardComplete the function that calculates the sum of the first n+1 terms of the geometric series a, ar, ar² ar³, arª ….. arn Note that the series begins with a and the last term is ar", in total there are n+1 terms. 1: # complete the function given the #variables a,r,n and return the value as series_sum. def sum geometric_series(a,r,n): # YOUR CODE HERE return series_sum print (sum_geometric_series (4.0, 5, 10))arrow_forward
- (java programming language) Write a Java program to do the following task: Assign your id number (example.. 2014299123) to an integer variable id_num Using reminder operator % on the id_num get the last 5 digits (99123) and store it in num If the num is between 0 and 30,000 (both included), display “You are in Group 1” Otherwise if the num is between 30001 and 60,000 (both included), display “You are in Group 2” Otherwise (num is between 60,001 and 99,999 (both included), display “You are in Group 3” Save your file as Q2.Javaarrow_forwardWhere is the void function for circumferencearrow_forwardOx34 + OX1F Result. (in hexadecimal) Overflow occurred? (Yes or No) When writing the result, do not including any prefixes (like "Ox"). For example, if the answer were Ox32, you would enter just 32.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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 PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
What Are Data Types?; Author: Jabrils;https://www.youtube.com/watch?v=A37-3lflh8I;License: Standard YouTube License, CC-BY
Data Types; Author: CS50;https://www.youtube.com/watch?v=Fc9htmvVZ9U;License: Standard Youtube License