A
Arash_89
Guest
Hello,
It is Recursively method and I want have one whole program and static keyword doesn't work.
List<List<int>> listPrint // Just be one in the whole program.
using System;
using System.Collections.Generic;
using System.Text;
namespace CSharp
{
class Program
{
static void Recursively(List<int> list)
{
List<List<int>> listPrint = new List<List<int>>();
if (list.Count == 1)
{
Console.WriteLine(list[0]);
return;
}
for (int i = 0; i < list.Count - 1; i++)
{
list = list + list[i + 1];
}
list.RemoveAt(list.Count - 1);
if (list.Count != 1)
listPrint.Add(list);
//Print(list);
Recursively(list);
}
static void Print(List<int> list)
{
for (int i = 0; i < list.Count; i++)
{
Console.Write(list + " ");
}
Console.WriteLine();
}
static void Main(string[] args)
{
List<int> mylist = new List<int>();
int i = 0;
int numberOfElements;
Console.WriteLine("Number of Elements??");
numberOfElements = Convert.ToInt32(Console.ReadLine());
while(i < numberOfElements)
{
Console.WriteLine("Number? ");
mylist.Add(Convert.ToInt32(Console.ReadLine()));
i++;
}
Console.WriteLine();
Recursively(mylist);
}
}
}
Continue reading...
It is Recursively method and I want have one whole program and static keyword doesn't work.
List<List<int>> listPrint // Just be one in the whole program.
using System;
using System.Collections.Generic;
using System.Text;
namespace CSharp
{
class Program
{
static void Recursively(List<int> list)
{
List<List<int>> listPrint = new List<List<int>>();
if (list.Count == 1)
{
Console.WriteLine(list[0]);
return;
}
for (int i = 0; i < list.Count - 1; i++)
{
list = list + list[i + 1];
}
list.RemoveAt(list.Count - 1);
if (list.Count != 1)
listPrint.Add(list);
//Print(list);
Recursively(list);
}
static void Print(List<int> list)
{
for (int i = 0; i < list.Count; i++)
{
Console.Write(list + " ");
}
Console.WriteLine();
}
static void Main(string[] args)
{
List<int> mylist = new List<int>();
int i = 0;
int numberOfElements;
Console.WriteLine("Number of Elements??");
numberOfElements = Convert.ToInt32(Console.ReadLine());
while(i < numberOfElements)
{
Console.WriteLine("Number? ");
mylist.Add(Convert.ToInt32(Console.ReadLine()));
i++;
}
Console.WriteLine();
Recursively(mylist);
}
}
}
Continue reading...