Write a program that generates all the factors of a number

Assignment Help Programming Languages
Reference no: EM13165789

Write a program that generates all the factors of a number entered by the user. For instance, the number 12 has the factors 2 * 2 * 3. This program has the following requirements:

 

A. The user must enter a positive integer. If the user enters something else, your program should output an error message and let the user enter a new value. Use a do/while loop to make sure the user input is successful.

 

B. The factors must be output in increasing order. The lowest factor your program should report is 2.

 

C. Your program should output 4 factors per line, each factor in a field of 10 characters. (Hint: the number of factors output determines when to output endl!)

 

D. You will need a while loop to report the factors. Here are some helpful hints:

 

1. If (a % b == 0) then a is a factor of b.

 

2. When you have found a factor, output the factor and then reduce the number you are working with by dividing the number by the factor... ie) b = b / a;

 

1. Design an algorithm in pseudocode to solve the problem. Make sure to include steps to get each input and to report the output. Include steps to deal with error cases as specified above.

 

 

2. Identify three test cases, one using a number with 4 factors, one using a negative number, and one using a number with more than 4 factors. For each of the three test cases show what inputs you will use and what your expected outputs should be.

 

 

 

3. Write the program to implement your algorithm. Test your program using your test cases.

 

 

 

 

 

Programming Problem 2

 

This program is designed to analyze the growth of two cities. Each city has a starting population and annual growth rate. The smaller city has the larger growth rate (required). Show the comparative populations of each city year by year until the smaller city has grown larger than the bigger city.

 

As an example, Dogville has a population of 5000 growing at 20% annually while Cattown has a population of 7000 growing at 10% annually. The projected populations are:

Year Dogville Cattown

1 6000 7700

2 7200 8470

3 8640 9317

4 10368 10249

 

1. Identify the inputs and outputs of the problem.

 

 

2. Identify the processing needed to convert the inputs to the outputs.

 

 

3. Design an algorithm in pseudocode to solve the problem. Make sure to include steps to get each input and to report each output.

 

 

4. Identify three significant test cases including one for incorrect input (ie Small town has lower growth rate). For each of the three test cases show what inputs you will use and calculate what your expected outputs should be.

 

 

 

5. Write the program to implement your algorithm. Test your program using your test cases.

 

 

Reference no: EM13165789

Questions Cloud

Javascript program that asks the use : Design a javascript program that asks the user for a username with at least eight characters, beginning with a letter and including at least one digit. Next, write a validation loop to ensure that these conditions have been met
Design, simulate and verify a 16-bit ripple-carry : Design, simulate and verify a 16-bit ripple-carry adder by performing the following additions/subtractions (the values of a and b are given in decimal): (i) (-10) + (100), (ii) (63) - (-127), (iii) (15) + (95), (iv) (-32) + (79), (v) (-59) + (-16)..
Displays a single character at 100 random screen : Write a program that displays a single character at 100 random screen locations, with a delay factor of 100 milliseconds.Hint: set the console window screen height to 200 at runtime.
Populate a one-dimensional array : Populate a one-dimensional array with the following grades in this order: 93, 61, 72, 45, 84, 51, 70, 83, 96, and 66. Use a loop to call a method from main() that adds
Write a program that generates all the factors of a number : Write a program that generates all the factors of a number entered by the user. For instance, the number 12 has the factors 2 * 2 * 3.
Java method for radix sort in binary : java method for radix sort in binary but I want to understand how to do it so please make it as simple as possible
C string and two int reference parameters : Write a complete function, not an entire program, that has a C string and two int reference parameters (call them a and b), returning nothing.
Reads a line of characters from the user : Write a segment of code (not an entire program) that reads a line of characters from the user and outputs "too long" if the user enters more than 5 characters (not counting hitting the enter/return key).
The "continue" and "break" statements : How are the "continue" and "break" statements different from the "exit" and "return" statements?

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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