Question: 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.

 Write a function called Factors of Number that takes as input

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!