Skip to content

Commit

Permalink
Print the binary representation of a given integer. closes rathoresri…
Browse files Browse the repository at this point in the history
  • Loading branch information
EdYuTo committed Oct 24, 2018
1 parent 2bf5215 commit 63b848e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions IntToBin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdlib.h>
#include <stdio.h>

void IntToBin(int num) {
if (num > 1 ) {
IntToBin(num>>1);
}
printf("%d", num%2);
return;
}

int main(int argc, char *argv[ ]) {
int integer;

if (argc == 1) {
printf("Type an Integer:\n");
scanf("%d", &integer);
} else if (argc == 2) {
integer = atoi(argv[argc-1]);
} else {
printf("Usage: %s [INTEGER]\n", argv[0]);
return -1;
}
if (integer >= 0) {
IntToBin(integer);
printf("\n");
} else {
printf("Invalid input.\n");
}
return 0;
}

0 comments on commit 63b848e

Please sign in to comment.