Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void decimal_to_binary(int decimal) {
- int binary[32],index=0;
- while (decimal>0) {
- binary[index]=decimal%2;
- decimal=decimal/2;
- index++;
- }
- printf(" Binary representation: ");
- for (int i=index-1;i>=0;i--) {
- printf("%d",binary[i]);
- }
- }
- int main() {
- int decimal;
- printf(" ");
- scanf("%d",&decimal);
- printf("Decimal number: %d", decimal);
- decimal_to_binary(decimal);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement