The Babylonian
1. Make a guess at the answer (you can pick n/2 as your initial guess).
4. Go back to step 2 for as many iterations as necessary. The more you repeat steps 2 and 3, the closer guess will become to the square root of n.
Write a
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Absolute Java (6th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Modern Database Management (12th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Starting Out with C++: Early Objects
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
- Make a program that asks for a width, and then prints a pyramid of that width. The pyramid must be of odd width, and if the user enters an even number the program should print "Please enter an odd number" and ask again. (It is ok if the program gives an error if the user enters a non-number). Example: Please enter the pyramid width 10Please enter an odd numberPlease enter the pyramid width 14Please enter an odd numberPlease enter the pyramid width 13 * *** ***** ******* ********* ************************ The first line should have 1 asterisk, the second 3, then 5, 7, 9 etc. The number of spaces before starting the asterisks is (n−i)/2 Where n is the width of the pyramid and i is the number of asterixes in the current line. Note that this is always a whole number, as n and i are odd and hence (n-i) is even.arrow_forwardWrite a program that calculates the equivalent resistance of a circuit. n electrical resistors with resistance values R1, R2,.., Rn are said to be connected in parallel if the same voltage is applied across each. Their equivalent resistance Reg is related to the values R1, R2, ..., Rn by: 1 1 1 1 + +...+ R R R, R. "eq Write a program that prompts the user to enter the resistance of n resistors. The user should be prompted continuously by using a while loop until a zero or negative value is entered (the program should count the number of resistors n entered by the user and store the values in an array). Use another separate loop to print the resistance values entered by the user and the equivalent resistance Reg. Test your program with R1= 1 kn, R2= 2 kn, R3= 4 kQ and R4= 8 kQ.arrow_forwardA regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is Area = ( n * s2 ) / (4 * tan( π/n) Here, s is the length of a side. Write a program that prompts the user to enter the number of sides and their length of a regular polygon and displays its area.arrow_forward
- A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome. Ex: If the input is: bob the output is: palindrome: bob Ex: If the input is: bobby the output is: not a palindrome: bobby Hint: Start by just handling single-word input, and submit for grading. Once passing single-word test cases, extend the program to handle phrases. If the input is a phrase, remove or ignore spaces. 367012.2549490.qx3zqy7 LAB 5.25.1: LAB: Palindrome 6/ 10 АCTIVITY LabProgram.java Load default template... 1 import java.util.Scanner; 2 3 public class LabProgram { public static void main(String[] args) { 4 Type your code here. */ } 7 } 8arrow_forwardA palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome. Ex: If the input is: bob the output is: palindrome: bob Ex: If the input is: bobby the output is: not a palindrome: bobby Hint: Start by removing spaces. Then check if the string equals itself in reverse.arrow_forwardWrite a program to get an integer input from the user. If the input is 25, take the length and breadth from the user and calculate the area of rectangle. [ Area of rectangle = length * breadth ] If the input is 40, get the side from the user and calculate the area of square. [ Area of square = side * side ] If the input is 65, get the radius from the user and calculate the area of circle. [ Area of circle = 3.14*r*r] Otherwise Display " Enter number 25 or 40 or 65 ".arrow_forward
- A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome. Ex: If the input is: bob the output is: bob is a palindrome Ex: If the input is: bobby the output is: bobby is not a palindrome import java.util.Scanner; public class LabProgram {public static void main(String[] args) {/* Type your code here. */arrow_forwardA palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome. Ex: If the input is: bob the output is: bob is a palindrome Ex: If the input is: bobby the output is: bobby is not a palindrome Hint: Start by removing spaces. Then check if a string is equivalent to it's reverse. pythonarrow_forwardA palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome. Ex: If the input is: bob the output is: bob is a palindrome Ex: If the input is: bobby the output is: bobby is not a palindrome Hint: Start by removing spaces. Then check if a string is equivalent to it's reverse. In python codearrow_forward
- You can approximate e using the following summation: Write a program that displays the e value for i = 10000, 20000, …, and 100000.arrow_forwardA palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome. Ex: If the input is: bob the output is: "bob" is a palindrome Ex: If the input is: bobby the output is: "bobby" is not a palindrome You must use a C-string to hold the user input. Make the maximum number of characters be 40. Hint: Start by just handling single-word input, and submit for grading. Once passing single-word test cases, extend the program to handle phrases. If the input is a phrase, remove or ignore spaces. 448070.2207206.qx3zy? LAB ACTIVITY 8.14.1: LAB: palindrome (C-string) 1 #include 2 // whatever C-string header files are necessary 3 using namespace std; 4 5 int main() { 6 7 8 9 10 11 const char ONE_SPACE= const char DOUBLE_QUOTE= /* Type your code here. */ return 0; main.cpp Load default template...arrow_forwardAn integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program to display each digit, starting with the rightmost digit. Your program should also determine whether or not the number is divisible by 9.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr