Advertisement
Derik_hacker

Untitled

Jan 2nd, 2024
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void conversion(int n) {
  4.    
  5.     int binaryNum[32];
  6.  
  7.     int i = 0;
  8.  
  9.     while (n > 0) {
  10.        
  11.         binaryNum[i] = n % 2;
  12.         n = n / 2;
  13.         i++;
  14.     }
  15.  
  16.     for (int j = i - 1; j >= 0; j--) {
  17.         printf("%d", binaryNum[j]);
  18.     }
  19. }
  20.  
  21. int main() {
  22.     int nombredecimal;
  23.  
  24.  
  25.     printf("Entrez un nombre décimal : ");
  26.     scanf("%d", &nombredecimal);
  27.  
  28.    
  29.     printf("La représentation binaire est : ");
  30.     conversion(nombredecimal);
  31.  
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement