Ask Question
30 December, 08:12

Write a function, factors, that takes an integer n, and returns a list of values that are the positive divisors of n. Note: 0 is not a divisor of any integer, 1 divides every number, and n divides itself.

+1
Answers (1)
  1. 30 December, 12:10
    0
    public int[] factors (int n)

    {

    int arr[]=new int[n];

    int count=0;

    for (int i=1; i<=n; i++)

    if (n%i==0)

    {

    arr[count]=i;

    count++;

    }

    return arr;

    }

    Explanation:

    Factors are the numbers you multiply to get another number. For instance, factors of 15 are 3 and 5, because 3*5 = 15.

    In the program, we have an array of length N to store the factors.

    Since we don't know the number of factors of N, so we have taken size of upper bound N to store list of factors in the array arr.

    Within the loop the number gets divide by Integers from 1 to that number until result is 0. If it is 0, that number is stored in array.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a function, factors, that takes an integer n, and returns a list of values that are the positive divisors of n. Note: 0 is not a ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers