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
3 Réponses
+ 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
+ 1
Calvin Thomas yeah thanks 😄
If possible send c approach also
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)