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
Web Development and Design Foundations with HTML5 (8th Edition)
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Management Information Systems: Managing The Digital Firm (16th Edition)
Electric Circuits. (11th Edition)
- Guessing Numbers---The problem is to guess what number a computer has in mind. You will write a program that randomly generatesan integer between 0 and 100, inclusive. The program prompts the user to enter a number continuously until the number matches the randomly generated number. For each user input, the program tells the user whetherthe input is too low or too high, so the user can make the next guess intelligently. Here is a sample run . (do it using while or do-whGuessing Numbers---The problem is to guess what number a computer has in mind. You will write a java program that randomly generates an integer between 0 and 100, inclusive. The program prompts the user to enter a number continuously until the number matches the randomly generated number. For each user input, the program tells the user whetherthe input is too low or too high, so the user can make the next guess intelligently. Here is a sample run . (do it using while or do-while)arrow_forwardWrite an algorithm in pseudocode for the following problem: Write a program that reads a series of daily high temperatures from the keyboard and then prints to the screen the number of days that each high was achieved. Assume that the temperatures will fall between -40 and 110, inclusive. You'll print the temperature and then the number of days for each temperature that was the high at least once. So your output will be in two columns. The key to this is that you'll have an array where the indices of the array represent the temperatures and the contents are the number of days where that temperature was the high.arrow_forwardPython Programming The Fibonacci sequence starts 1, 1, 2, 3, 5, 8, . ... Each number in the sequence (after the first two) is the sum of the previous two. Write a program that computes and outputs the nth Fibonacci number, where n is a value entered by the user.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 ACTIVITY LabProgram.java Load default template.. 1 import java.util.Scanner; 3 public class LabProgram { public static void main(String[] args) { /* Type your code here. */ } 7 } 4 5 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_forwardYou can approximate e using the following summation: Write a program that displays the e value for i = 10000, 20000, …, and 100000.arrow_forward
- Write 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_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 import java.util.Scanner; public class LabProgram {public static void main(String[] args) {/* Type your code here. */arrow_forward
- Write 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_forwardpythonarrow_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_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr