-
Notifications
You must be signed in to change notification settings - Fork 1
/
exe11.c
47 lines (38 loc) · 819 Bytes
/
exe11.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
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
int main (){
char bin[10];
int i, a, soma, pos;
fgets(bin, 11, stdin);
if (bin[0] == '1'){
for (i=1; i<10; i++){
if (bin[i] == '1'){
bin[i] = '0';
} else {
bin[i] = '1';
}
}
a = 1;
for (i=9; i>0 && a == 1; i--){
if (bin[i] == '0'){
bin[i] = '1';
a = 0;
} else{
bin[i] = '0';
}
}
}
pos = 1;
soma = 0;
for (i=9; i>0; i--){
if (bin[i] == '1'){
soma = soma + pos;
}
pos = pos * 2;
}
if (bin[0] == '1'){
soma = soma * -1;
}
printf("%d", soma);
return 0;
}