#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
// Stack
int decimal, q, r;
int counter, i;
char *binary = NULL;
char *aux;
printf("Digite um número em base decimal: ");
counter = 1;
while (decimal >= 1) {
q = decimal / 2;
r = decimal - (q * 2);
// Heap
aux
= (char *) malloc(counter
* sizeof(char)); if (binary != NULL) {
memcpy(aux
, binary
, counter
-1); }
binary = aux;
if (r == 0) {
binary[counter-1] = 48; //'0';
} else {
binary[counter-1] = 49; //'1';
}
//printf("resto %d = %d\n", counter, r);
counter++;
decimal = q;
}
//printf("ultimo quociente = %d\n", q);
printf("Resultado em binário = "); for (i = counter-1; i >= 0; i--) {
}
return 0;
}
I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgKmFyZ3ZbXSkgewoJLy8gU3RhY2sKCWludCBkZWNpbWFsLCBxLCByOwoJaW50IGNvdW50ZXIsIGk7CgljaGFyICpiaW5hcnkgPSBOVUxMOwoJY2hhciAqYXV4OwoKCXByaW50ZigiRGlnaXRlIHVtIG7Dg8K6bWVybyBlbSBiYXNlIGRlY2ltYWw6ICIpOwoJc2NhbmYoIiVkIiwgJmRlY2ltYWwpOwoKCWNvdW50ZXIgPSAxOwoJd2hpbGUgKGRlY2ltYWwgPj0gMSkgewoJCXEgPSBkZWNpbWFsIC8gMjsKCQlyID0gZGVjaW1hbCAtIChxICogMik7CgoJCS8vIEhlYXAKCQlhdXggPSAoY2hhciAqKSBtYWxsb2MoY291bnRlciAqIHNpemVvZihjaGFyKSk7CgkJaWYgKGJpbmFyeSAhPSBOVUxMKSB7CgkJCW1lbWNweShhdXgsIGJpbmFyeSwgY291bnRlci0xKTsKCQkJZnJlZShiaW5hcnkpOwoJCX0KCQliaW5hcnkgPSBhdXg7CgoJCWlmIChyID09IDApIHsKCQkJYmluYXJ5W2NvdW50ZXItMV0gP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