Skip to content

Commit

Permalink
Merge pull request #475 from EdYuTo/master
Browse files Browse the repository at this point in the history
Int to Bin and Swap #457, #456
  • Loading branch information
Srikant Singh authored Oct 25, 2018
2 parents b4ed6b8 + d5e1ed9 commit 94d0ae8
Show file tree
Hide file tree
Showing 2 changed files with 47 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;
}
16 changes: 16 additions & 0 deletions Swap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>

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

printf("Type two integers:\n");
scanf("%d %d", &a, &b);

printf("Before Swap: A = [%d], B = [%d]\n", a, b);
a = a^b;
b = a^b;
a = a^b;
printf("After Swap: A = [%d], B = [%d]\n", a, b);

return 0;
}

0 comments on commit 94d0ae8

Please sign in to comment.