Untitled

mail@pastecode.io avatar
unknown
plain_text
15 days ago
526 B
2
Indexable
Never
#include "../{}/pilha.h"

#include <stdio.h>

void convertBin(int n){
    int quoc, resto;
    Stack pilha;
    inicialize(&pilha);

    while(n != 0){
        quoc = n / 2;
        resto = n % 2;

        if(isFull(pilha) == 0){
            push(&pilha, resto);  
        } else{ return; }

        n = quoc;
    }

    while(isEmpty(pilha) == 0){
        printf("%d", pop(&pilha));
    }
    printf("\n");
}

int main(){
    int num;
    scanf("%d", &num);
    convertBin(num);
    return 0;
}
Leave a Comment