I have declared an integer array in which i am storing the factors of a number.....I want that array to print the number in it's elements, but I have failed too; Is there a way to access the array and it's elements outside the loop in which they are declared?
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Enter number : ");
int num = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= num; i++)
{
int[] factor = new int[i];
if (num % i == 0)
{
Console.WriteLine("Number going in i: " + i);
factor[i - 1] = i;
};
}
//Not working
for (int i = 0; i < factor.length; i++)
{
Console.WriteLine(factor[i]);
}
}
}