Advertisement
Sierra_ONE

Conversion: Decimal to Binary (Alternative)

Sep 17th, 2023 (edited)
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.33 KB | Source Code | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void){
  4.  
  5.     int decimal,binary,position;
  6.    
  7.     //decimal = 76;
  8.     position = 1;
  9.     binary = 0;
  10.    
  11.     printf("Enter decimal number: ");
  12.     scanf("%d",&decimal);
  13.    
  14.     while (decimal > 0){
  15.         binary += (decimal % 2) * position;
  16.         decimal /= 2;
  17.         position *= 10;
  18.     }
  19.  
  20.     printf("%d",binary);
  21.    
  22.    
  23.    
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement