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
Derive the run time of the following code
What is the correct answer in the following?
TROUBLESHOOTING: Fix the errors in the code below and run the script with your modified code
function [x,numIter,omega] = gaussSeidel(func,x,maxIter,epsilon)
% Solves Ax = b by Gauss-Seidel method with relaxation.
% USAGE: [x,numIter,omega] = gaussSeidel(func,x,maxIter,epsilon)
% INPUT:
% func = handle of function that returns improved x using
% x = starting solution vector
% maxIter = allowable number of iterations (default is 500)
% epsilon = error tolerance (default is 1.0e-9)
% OUTPUT:
% x = solution vector
% numIter = number of iterations carried out
% omega = computed relaxation factor
if nargin < 4; epsilon = 1.0e-9; end
if nargin < 3; maxIter = 500; end
k = 10; p = 1; omega = 1;
for numIter = 1:maxIter
xOld = x;
x = feval(func,x,omega);
dx = sqrt(dot(x - xOld,x - xOld));
if dx < epsilon; return; end
if numIter == k; dx1 = dx; end
if numIter == k + p
omega = 2/(1 + sqrt(1 - (dx/dx1)ˆ(1/p)));
end
end
error(’Too many iterations’)
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
- Do all and completelyarrow_forwardPython: A ball falls freely from a height of 100 meters, and bounces back to half of its original height after each landing; again, how many meters does it travel when it hits the ground for the 10th time? How high is the 10th rally?arrow_forwardPlease show the work necessary to get the answer.arrow_forward
- SUCCESSIVE-OVER-RELAXATION Method TROUBLESHOOTING: Fix the errors in the code below and run the script with your modified code and screenshot your output and codes with answer function [x,numIter,omega] = gaussSeidel(func,x,maxIter,epsilon) % Solves Ax = b by Gauss-Seidel method with relaxation. % USAGE: [x,numIter,omega] = gaussSeidel(func,x,maxIter,epsilon) % INPUT: % func = handle of function that returns improved x using % x = starting solution vector % maxIter = allowable number of iterations (default is 500) % epsilon = error tolerance (default is 1.0e-9) % OUTPUT: % x = solution vector % numIter = number of iterations carried out % omega = computed relaxation factor if nargin < 4; epsilon = 1.0e-9; end if nargin < 3; maxIter = 500; end k = 10; p = 1; omega = 1; for numIter = 1:maxIter xOld = x; x = feval(func,x,omega); dx = sqrt(dot(x - xOld,x - xOld)); if dx < epsilon; return; end if numIter == k; dx1 = dx; end if numIter == k + p omega = 2/(1 + sqrt(1 -…arrow_forwardPlease show work for all properties.arrow_forwardThe solution can be handwritten b) Trace the following recursive method for the function call “isPalindrome(rotator)” and show the output result.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning