@acwoss/

Conversor decimal/binário

C

https://pt.stackoverflow.com/q/199742/5878

fork
loading
Files
  • main.c

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6022638958246493","path":"main.c","file":{"path":"main.c","content":{"asEncoding":{"base64":"I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBtYWluKCkgewoKICAgIGludCBudW07CiAgICBpbnQgYmluWzddOwogICAgaW50IGF1eDsKCiAgICBwcmludGYoIkRpZ2l0ZSBvIG7Dum1lcm8gKGJhc2UgZGVjaW1hbCkgcGFyYSBzZXIgY29udmVydGlkbzogIik7CiAgICBzY2FuZigiJWQiLCAmbnVtKTsKCiAgICBmb3IgKGF1eCA9IDc7IGF1eCA+PSAwOyBhdXgtLSkgewogICAgICAgIGlmIChudW0gJSAyID09IDApIHsKICAgICAgICAgICAgYmluW2F1eF0gPSAwOwogICAgICAgICAgICBudW0gPSBudW0gLyAyOwogICAgICAgIH0KICAgICAgICBlbHNlIHsKICAgICAgICAgICAgYmluW2F1eF0gPSAxOwogICAgICAgICAgICBudW0gPSBudW0gLyAyOwogICAgICAgIH0KICAgIH0KCiAgICBmb3IgKGF1eCA9IDA7IGF1eCA8PSA3OyBhdXgrKykgewogICAgICAgIHByaW50ZigiJWQiLCBiaW5bYXV4XSk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0="},"asBuffer":null},"loaded":true}}
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
#include <stdio.h>
#include <stdlib.h>

int main() {

    int num;
    int bin[7];
    int aux;

    printf("Digite o número (base decimal) para ser convertido: ");
    scanf("%d", &num);

    for (aux = 7; aux >= 0; aux--) {
        if (num % 2 == 0) {
            bin[aux] = 0;
            num = num / 2;
        }
        else {
            bin[aux] = 1;
            num = num / 2;
        }
    }

    for (aux = 0; aux <= 7; aux++) {
        printf("%d", bin[aux]);
    }

    return 0;
}