-
Notifications
You must be signed in to change notification settings - Fork 8
/
Arrays count.c
40 lines (35 loc) · 805 Bytes
/
Arrays count.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<stdio.h>
#include <stdlib.h>
int main()
{
int n,index,comboctr,count=0,sum=0,elemcount=0,copyindex=0;
scanf("%d",&n);
int arr[n],triparr[n];
for(index=0;index<n;index++)
{
scanf("%d",&arr[index]);
}
for(comboctr=1;comboctr < (1 << n);comboctr++)//for the combination counter (2 power n)-1.
{
for(index=0;index <n;index++)//comparing with our string positon in order to perform the bitwise
operation.
{
if(comboctr & (1 << index))//comparing combo and index ctr,
{
//printf("%c",str[index]);
elemcount++;
sum+=arr[index];
triparr[copyindex++]=arr[index];
}
}
if(sum==0)
{
printf("\n");
for(index=0;index<elemcount;index++)
{
printf("%d",triparr[index]);
}
}
}
//printf("%d",count);
}