-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha.c
More file actions
35 lines (31 loc) · 625 Bytes
/
a.c
File metadata and controls
35 lines (31 loc) · 625 Bytes
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
#include <stdio.h>
#define n 5
void dec2bin(int i, int x[]);
int main(void)
{
int a[n] = {8, 12, 22, 15, 13};
int b = 47;
int x[n] = {0, 0, 0, 0, 0};
int sum;
int p = 0;
for (int i = 0; i < 32; i++) {
dec2bin(i, x);
sum = 0;
for (int j = 0; j < n; j++) {
sum += a[j] * x[j];
p++;
}
if (sum == b) {
printf("%d\nYES\n",p);
return 0;
}
}
printf("%d\n",p);
printf("NO\n");
return 0;
}
void dec2bin(int i, int x[]) {
for (int j = 0; j < n; j++) {
x[j] = (i >> j) & 1;
}
}