C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 4, Problem 4.27E
Program Plan Intro
- Declare three nested FOR loops where each loop iterates up to 500.
- Inside the innermost FOR loop, check the condition for Pythagorean triples(If the sum of the squares of two sides is equal to the square of the third side, it is a Pythagorean triple).
- Print those values that satisfy the condition.
Summary Introduction:
The program is written in order to print Pythagorean triples less than 500.
Program description:
The main purpose of this program is to display the lengths of the three sides of a Pythagorean triangle. For this purpose, three nested FOR loops have been used with a simple print statement to display the values.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
[Fish
Tank]
You play with a clown fish that has an initial size so. The fish can eat other fish in a tank organized in m columns and n rows. The fish at column i and row j has a positive size si,j.
When your fish eats another fish, it grows by that amount. For example, if your clown fish has a size of 10 and eats a fish of size 5, it becomes of size 15. You cannot eat a fish that
is bigger than your size. The game starts by eating any fish in the first (left-most) column that is not bigger than yours. After that, you advance one column at a time by moving
right. You have only three allowed moves. You either stay at the same row, move one row higher or one row lower. You will always move to the right. Thus, you will make exactly
m moves to advance from left to right. Your goal is to exit the fish tank from the right with the biggest possible size.
The figure below shows an example with the best answer highlighted. In this case, the final fish size is 71 (10+8+7+24+22). You are required…
Heat capacity of a solid: Debye's theory of solids gives the heat capacity of a solid at
temperature T to be
3
T
rOp/T
Cy = 9VpkB
(e* – 1)2 dx,
-
where V is the volume of the solid, p is the number density of atoms, kg is Boltzmann's
constant, and 0D is the so-called Debye temperature, a property of solids that depends on
their density and speed of sound.
Develop a computer code to evaluate Cy (T) for a given value of the temperature, for a
sample consisting of 1000 cubic centimeters of solid aluminum, which has a number
density of p = 6.022 x 1028m-3 and a Debye temperature of 0p = 428K. The
Boltzmann's constant kg =
1.380649 x 10-23 J · K-1.
Please evaluate the integral with the following methods:
(a) MATLAB adaptive Simpson quadrature, [Q.FCNT] = QUAD(FUN,A,B,TOL)
with TOL =le-10.
[Unbalanced Rod]
Given a set of n weights {w₁,..., wn} and a rod of length n - 1 inches, we can attach the weights to the rod at hooks placed at one inch distances apart as shown in the figure
below.
-1".
/10
2
3
12
2
4
We can attach a weight to any hook but no two weights can be attached to the same hook and we have to attach all the weights. For any given assignment of weights to hooks, we
can compute the location of the center of mass of the rod and the weights according to the following equation (neglecting the weights of the rod and the hooks).
where 0 ≤ Pi≤n-1 is the position of weight along the rod.
For example, in the figure shown above, the center of mass is computed as
C=
C =
i Wi Pi
Σi Wi
10 0+2 1+3·2+4·3+12.4 +2.5
10+2+3+4+12+2
78
33
The problem is to find an assignment of weights to hooks that makes the center of mass as far as possible to the left, i.e., minimize the value of c.
Answer the following questions.
1. Describe a greedy algorithm that finds the assignments that…
Chapter 4 Solutions
C How to Program (8th Edition)
Ch. 4 - Find the error in each of the following. (Note:...Ch. 4 - State which values of the control variable x are...Ch. 4 - Write for statements that print the following...Ch. 4 - Prob. 4.8ECh. 4 - (Sum a Sequence of Integers) Write a program that...Ch. 4 - (Average a Sequence of Integers) Write a program...Ch. 4 - (Find the Smallest) Write a program that finds the...Ch. 4 - (Calculating the Sum of Even Integers) Write a...Ch. 4 - (Calculating the Product of Odd Integers) Write a...Ch. 4 - (Factorials) The factorial function is used...
Ch. 4 - (Modified Compound-Interest Program) Modify the...Ch. 4 - (Triangle-Printing Program) Write a program that...Ch. 4 - (Calculating Credit Limits) Collecting money...Ch. 4 - (Bar-Chart Printing Program) One interesting...Ch. 4 - (Calculating Sales)An online retailer sells five...Ch. 4 - (Truth Tables) Complete the following truth tables...Ch. 4 - Rewrite the program of Fig. 4.2 so that the...Ch. 4 - Prob. 4.22ECh. 4 - (Calculating the Compound Interest with...Ch. 4 - Assume i=1,j=2,k=3andm=2. What does each of the...Ch. 4 - (Table of Decimal, Binary, Octal and Hexadecimal...Ch. 4 - (Calculating the Value of )Calculate the value of...Ch. 4 - Prob. 4.27ECh. 4 - (Calculating Weekly Pay)A company pays its...Ch. 4 - (De Morgans Laws)In this chapter, we discussed the...Ch. 4 - (Replacing switch with if ... else)Rewrite the...Ch. 4 - (Diamond-Printing Program)Write a program that...Ch. 4 - (Modified Diamond-Printing Program)Modify the...Ch. 4 - (Roman-Numeral Equivalent of Decimal Values)Write...Ch. 4 - Describe the process you would use to replace a do...Ch. 4 - A criticism of the break statement and the...Ch. 4 - Prob. 4.36ECh. 4 - Describe in general how you would remove any...Ch. 4 - (The Twelve Days of Christmas Song) Write a...Ch. 4 - (Limitations of Floating-Point Numbers for...Ch. 4 - (World Population Growth) World population has...Ch. 4 - (Tax Plan Alternatives; The FairTax) There are...
Knowledge Booster
Similar questions
- 2, Towers of Hanoi Problem. (10 points) The Towers of Hanoi is a famous problem for studying recursion in computer science and searching in artificial intelligence. We start with N discs of varying sizes on a peg (stacked in order according to size), and two empty pegs. We are allowed to move a disc from one peg to another, but we are never allowed to move a larger disc on top of a smaller disc. The goal is to move all the discs to the rightmost peg (see figure). To solve the problem by using search methods, we need first formulate the problem. Supposing there are K pegs and N disk. Answer the following questions. (1) Determine a state representation for this problem. (4points) (2) What is the size of the state space? (3 points) (3) Supposing K=3, N=4, what is the start state by using your proposed state representation method and what is the goal state? (3 points)arrow_forward(Algebra: solve linear equations) Write a function that solves the following 2 x 2 system of linear equation: aoox + a01y = bo boa11 - bjao1 X = bja00 - boa10 a10x + any = bị y = agoa11 dooa11 - d01a10 The function header is const int SIZE = 2; bool linearEquation(const double a[][SIZE], const double b[], double result[]); The function returns false if apo1 - aoja10 is 0; otherwise, returns true. Write a test program that prompts the user to enter ao0. d01, a10, a11, bo, bị, and display the result. If aooa11 – a0ia10 is 0, report that "The equation has no solution". A sample run is similar to Programming Exercise 3.3.arrow_forward[using C++]Masterchef pankaj recently baked a big nepotialn pizza that can be represented as a grid of N rows and M columns, each cell can be either empty or contain a jalapeno, pankaj wants to cut out a sub-rectangle from the pizza which contains even number of jalapenos. Before cutting such a sub-rectangle, he is interested in knowing how many sub-rectangles are there which contains even number of jalapenos.First line of input consist of two integers P and Q. Each of the next P lines contains a string of length Q, j-th character of i-th string is 1 if the corresponding cell contains a jalapeno otherwise it's 0.Output a single integer, the number of sub rectangles which contains even number of jalapeno.Sample Input:2 22101Output:5arrow_forward
- (x² If h(x) X 2 , then 2arrow_forwardIn C Programming Language solve the following programarrow_forward[In C language] The concept of a "drunkard's walk" involves an individual who starts walking aimlessly from a lamp post. With each step they take, they move randomly either north, south, east, or west, each with a 25% probability. As the individual takes more steps, they tend to forget where they started and continue taking random steps. The objective is to determine how far the individual will be from the starting point (0,0) after taking N number of steps. To simulate this random walking motion for N steps, we can create a computer program. This program should ask the user to input an integer representing the number of steps to be taken. It should work for any positive value of steps, even for a large number. However, if the user enters an invalid number (such as a negative value), the program should display an error message. After each step, the program should show the current location of the random walker with respect to the origin (lamp post). Finally, when the random…arrow_forward
- (Recursive Greatest Common Divisor) The greatest common divisor of integers x and y isthe largest integer that evenly divides both x and y. Write a recursive function gcd that returns thegreatest common divisor of x and y. The gcd of x and y is defined recursively as follows: If y is equalto 0, then gcd(x, y) is x; otherwise gcd(x, y) is gcd(y, x % y), where % is the remainder operator.arrow_forward(True or False) Seven different positive integers are randomly chosen between 1 and 2022 (including 1 and 2022).There must be a pair of these integers has a difference that is a multiple of 6.arrow_forward(GREATEST COMMON DIVISOR) The greatest common divisor of integers x and y is the largest integer that evenly divides into both x and y. Write and test a recursive function gcd that returns the greatest common divisor of x and y. The gcd of x and y is defined recursively as follows: If y is equal to 0, then gcd (x, y) is x; otherwise, gcd (x, y) is gcd (y, x % y), where % is the remainder operator.arrow_forward
- computer science | c++ code | it's not graded. Correct answer will upvoted else downvoted. It is given a non-negative integer x, the decimal portrayal of which contains n digits. You need to shading every its digit in red or dark, so the number shaped by the red digits is separable by A, and the number framed by the dark digits is detachable by B. No less than one digit should be shaded in every one of two tones. Consider, the include of digits hued in red is r and the include of digits hued in dark is b. Among all potential colorings of the given number x, you need to output any to such an extent that the worth of |r−b| is the base conceivable. Note that the number x and the numbers shaped by digits of each tone, may contain driving zeros. Input :The principal line contains one integer t (1≤t≤10) — the number of experiments. Then, at that point, t experiments follow. Each experiment comprises of two lines. The main line contains three integers n, A, B (2≤n≤40, 1≤A,B≤40).…arrow_forwardExercise 1: (Design of algorithm to find greatest common divisor) In mathematics, the greatest common divisor (gcd) of two or more integers is the largest positive integer that divides each of the integers. For example, the gcd of 8 and 12 is 4. Why? Divisors of 8 are 1, 2, 4, 8. Divisors of 12 are 1, 2, 4, 6, 12 Thus, the common divisors of 8 and 12 are 1, 2, 4. Out of these common divisors, the greatest one is 4. Therefore, the greatest common divisor (gcd) of 8 and 12 is 4. Write a programming code for a function FindGCD(m,n) that find the greatest common divisor. You can use any language of Java/C++/Python/Octave. Find GCD Algorithm: Step 1 Make an array to store common divisors of two integers m, n. Step 2 Check all the integers from 1 to minimun(m,n) whether they divide both m, n. If yes, add it to the array. Step 3 Return the maximum number in the array.arrow_forwardRequired: Amitabh had a magical cat. That cat once fell down an empty well. As the walls of the well were not completely vertical, the cat could climb up the well. In one day, the cat can climb 1 unit height and the height of the well is h units. The cat starts at the bottom. Every day, a cat would divide into 2 cats. One of them would climb up 1 unit. The other would wait for help. But while waiting it would fall asleep and roll down 1 unit, unless it is already at the bottom, in which case it just remains there. When a cat would reach the top, it would run home toAmitabh. (Schrodinger doesn't know that some of the cats are in a well and so he can't rescue them). It has been d days since the cat fell into the well. How many cats would come out of the well today? You would notice that the number of cats grows very large with each passing day, so output the answer modulo 10^9+7. d = 0 means that the cat has fallen just now and so there's just one cat at the bottom of the well. So you…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education