print all possible combination of array ellements(integers).

Posted by Nagarjuna6087 under C# on 8/23/2016 | Points: 10 | Views : 305 | Status : [Member] | Replies : 2
hi,
i want know how to write this program.

example:
input:1,2,3,4

output:1,2,3,4,
12,13,14,23,24,......................1234




Responses

Posted by: Manideepgoud on: 8/23/2016 [Member] Starter | Points: 25

Up
0
Down
Dear nagarjuna6087

Please follow this url for arrays
http://www.dotnetfunda.com/articles/show/2947/arrays-declaration-and-default-initialization-of-arrays-in-csharp

Nagarjuna6087, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A2H on: 8/23/2016 [Member] [MVP] Silver | Points: 25

Up
0
Down
You are trying to populate Powerset of an array, if so then you can try with the below code
public static IEnumerable<IEnumerable<T>> GetPowerSet<T>(IEnumerable<T> input)
{
var seed = new List<IEnumerable<T>>()
{
Enumerable.Empty<T>()}

as IEnumerable<IEnumerable<T>>;
return input.Aggregate(seed, (a, b) => a.Concat(a.Select(x => x.Concat(new List<T>()
{
b
}

))));
}


Ensure that you added necessary references to your page before using this logic.

Source UK :
 http://rosettacode.org/wiki/Power_set#C.23


Thanks,
A2H
My Blog

Nagarjuna6087, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response