Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int decimal;
- char binary[100];
- printf("Enter a decimal number: ");
- scanf("%d", &decimal);
- int n = 1;
- while(pow(2, n) <= decimal)
- {
- n++;
- }
- int i;
- for(i = n-1; i >= 0; i--)
- {
- binary[i] = (decimal % 2) + '0';
- decimal = decimal/2;
- }
- binary[n] = '\0';
- printf("%s\n", binary);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement