Answer:
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;
}
Step-by-step 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.