Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function called Factors of Number that takes as input a positive integer and returns the factors of the positive integer as an array.

image text in transcribed
Write a function called Factors of Number that takes as input a positive integer and returns the factors of the positive integer as an array. For example, if the integer is 6, the output is an array consisting of the values [1 2 3 6]. Test your function on the following numbers: 26, 64, 97 and 187 1 and the number itself are always factors. To find other factors, check up to the floor of the squareroot of the number. For example, if the number is 10, floor (Squareroot 10) = 3. 10 mod 2 equals 0. That means 2 and 5 (which is 10/2) are factors. In this case, it is OK to dynamically grow your array. 10 mod 3 equals 1, which means 3 is not a factor. Since we check up to 3, this completes the function and we return [1 10 2 5] as the factors of 10 (order is not important)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago