Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Print input integer in binary
- #include <stdio.h>
- #include <math.h>
- int main() {
- long long n,nearest;
- scanf_s("%lld", &n);
- nearest = pow(2,floor(log2l((long double)n)));
- printf("%lld - %lld\n\n", n, nearest);
- while(nearest){
- if (n - nearest >= 0) {
- printf("1");
- n -= nearest;
- }
- else
- printf("0");
- nearest /= 2;
- printf("(%lld)", n);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment