Ask Question
23 June, 09:20

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.

+3
Answers (1)
  1. 23 June, 09:31
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers