Create author-filename

Assignment Help C/C++ Programming
Reference no: EM13761142

AUTHOR: your name

FILENAME: title of the source file

SPECIFICATION: description of the program

FOR: CSE 110: homework #- days and time of your class

TIME SPENT: how long it took you to complete the assignment

Part #1: Written Exercises
1. (4 pts) What do the following loops print?
a) for (int i = 10; i > 1; i--)
System.out.print(i + " ");
b) int j = 1;
while (j < 20) {
if (j % 5 == 0)
System.out.print(j + " ");
j += 2;
}
1
2.Given the following code segment that reads in a String str:

String str = in.nextLine();

Write a loop that will print out the value entered into str in reverse. That is if the user entered "Harry", the loop should print "yrraH". This does not have to be a complete program, but you should test your loop inside a complete program. Section 4.7.2 in the book and the Examples for Loops lecture video show some String loop examples with a for loop.

Part #2 - Programming (10 pts)

Write a program called Assignment3 (saved in a file Assignment3.java) that computes the greatest common divisor of two given integers. One of the oldest numerical algorithms was described by the Greek mathematician, Euclid, in 300 B.C. It is a simple but very effective algorithm that computes the greatest common divisor of two given integers. For instance, given integers 24 and 18, the greatest common divisor is 6, because 6 is the largest integer that divides evenly into both 24 and 18. We will denote the greatest common divisor of x and y as gcd(x, y).

The algorithm is based on the clever idea that the gcd(x, y) = gcd(x - y, y) if x >= y and gcd(x, y) = gcd(x, y - x) if x < y. The algorithm consists of a series of steps (loop iterations) where the "larger" integer is replaced by the difference of the larger and smaller integer. This continues until the two values are equal. That is then the gcd. You are required to do the following:

• Prompt the user to enter two integers and read them from the keyboard.
• Create a loop, and inside of it replace the larger integer with the difference between the larger integer and the smaller integer (if the integers are equal you may choose either one as the "larger") during each iteration. You will need to use an if/else statement to determine the larger value.
• Continue looping until the two integers are equal.
• Print out the remaining value as the gcd. See the sample output below.

Sample Outputs
Sample 1:
Enter the first integer: 72
Enter the second integer: 54
The gcd of 72 and 54 is 18
Sample 2:
Enter the first integer: 18
Enter the second integer: 24
The gcd of 18 and 24 is 6

Reference no: EM13761142

Questions Cloud

Error analysis and correcting entry : The reported net incomes for the first 2 years of US Books Corp. were as follows: 2013, $268,000; and 2014, $412,000. Early in 2015, the following errors were discovered.
Identify suppliers with capabilities for global business : Identify suppliers with capabilities for global business. Strategy of integrated supply approach with distributors
Determine how high the water can rise on the left side : What is the current factor of safety against a quick condition at A‘? (The FS is defined as the ratio of the critical gradient to the existing gradient).
Explain rosickys relationship with his daughter-in-law : Explain Rosicky's relationship with his daughter-in-law, Polly. Why does she feel so out of place on the farm? Why is Anton Rosicky the only one capable of making her feel welcome and comfortable?
Create author-filename : FILENAME: title of the source file,SPECIFICATION: description of the program
Fundamental concepts and principles in accounting : Identify and explain the fundamental concepts and principles in accounting, the components of the accounting equation, the primary financial accounting equation, and financial statements and reports.
Describe the target customer for the product : Describe the target customer for the product/service in terms of relevant characteristics that impact the marketing strategy, including location (how it should be reached) and buying habits.
Discuss the importance of disaster recovery : Discuss the importance of disaster recovery and/or business continuity planning with respect to maintaining the confidentiality, integrity, and availability of information and information systems
What are the two explanations of hayys origin : What is the point Ibn Tuffayl is trying to make with the blind child allegory (p. 97)? What is he trying to show or suggest? What are the two explanations of Hayy's origin? What is the difference between them?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a c++ statement that outputs the data stored

Write a C++ statement that declares student to be a personType object, and initialize its first name to "Buddy" and last name to "Arora".

  Calculating the gcd greatest common divisor

Write a C++ code for calculating the GCD Greatest Common Divisor between two positive integer numbers. You  should  use Euclid's  original  subtraction  based  GCD algorithm ( not  using  modulo operator).

  Display a year-by-year depreciation schedule

Create GUI screen interface that accepts input and shows output and resize the GUI screen & the list box to best fit the output displayed

  Writing function that computes leap years

Write down function that computes leap years. Function prototype is as follows: Write function body which returns true if year is a leap year and false if year is not a leap year.

  Reverses the characters in a character array

Write the function reverseit that reverses the characters in a character array. You must also write main that calls reverseit.

  Questionnbspnbspi have a product called neverwet that

questionnbspnbspi have a product called neverwet that creates a hydrophobic surface on stuff. theres a base and top

  Computers have trended to larger word

Since the beginning, computers have trended to larger word sizes, 8 to 16 to 32 and now some 64 bit computers. Explain a pro or a con in a computer with a larger word size, or comment on someone else's pro or con.

  Assignment 1write a program using vectors and iterators

assignment 1write a program using vectors and iterators that allows a user to maintain a personal list of dvd titles.

  Evaluate the circumference of a circle

Write a program that will call a function to calculate the area of a circle, and call another function to calculate the circumference of a circle.

  Create a function gcd

Create a function gcd(a, b) that receives two integers and returns the greatest common denominator of the two integers.

  Write a program that skip s leading whitespace character

a) Write a program that skip s leading whitespace character s in each line of the pro vided data file CPPHumor .txt . Save the results in a new file

  Use a loop in main to efficiently handle all three persons

Plan and finish writing the main program, and all the functions, including a constructor. Use a loop in main to efficiently handle all three persons' data.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd