0

Printing Sub arrays in array

Let array a={1,2,3,4} Then I store them as arrays like {1} {2} {3} {1,2} {2,3} {3,4} {1,2,3} {2,3,4} {1,2,3,4} At least tell me how to print numbers like that You can tell in C

9th Jul 2021, 7:12 AM
SRI SIVA LAKSHMANA REDDY DWARAMPUDI
SRI SIVA LAKSHMANA REDDY DWARAMPUDI - avatar
3 Respostas
+ 2
SRI SIVA LAKSHMANA REDDY DWARAMPUDI Here's a possible solution: from itertools import combinations as k list = (1, 2, 3, 4) for i in range(1, len(list)): print(*map(set, tuple(k(list, i))), sep="\n") print(set(list)) # Hope this helps
9th Jul 2021, 7:24 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Calvin Thomas yeah thanks 😄 If possible send c approach also
9th Jul 2021, 7:56 AM
SRI SIVA LAKSHMANA REDDY DWARAMPUDI
SRI SIVA LAKSHMANA REDDY DWARAMPUDI - avatar
0
In python you can do [ a[n:i] for i in range(len(a)+1) for n in range(i) ] In C the approach is similar (but it depends on how you handle arrays), loop i from 0 to array lenght and loop j from 0 to i and copy the data from a+j to a+i inside the result array (the position in the result array should be i*j + j)
9th Jul 2021, 1:44 PM
Angelo
Angelo - avatar