-
-
Save CraigRodrigues/33af36647355ce95020c26cc67811691 to your computer and use it in GitHub Desktop.
CS50x Coding Contest 2016 Practice - Decimal to Binary Conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include "cs50.h" | |
int main(void) | |
{ | |
int i = 0; | |
int remainder; | |
int binary[50]; //this is an array placeholder for the binary digits. Once we put each one in there we will print it out again but backwards. | |
int decimal = GetInt(); | |
while (decimal != 0) | |
{ | |
binary[i] = decimal % 2; | |
decimal = decimal / 2; | |
i++; | |
} | |
for (int j = i - 1; j >= 0; j--) | |
printf("%d", binary[j]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment