Advertisement
Guest User

Untitled

a guest
Nov 9th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.78 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3.                             Online C Compiler.
  4.                 Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10.  
  11. int main()
  12. {  
  13.     string nombr;
  14.     int a,d,i,poid,reinit, nombrefinale;
  15.     int tab[30];
  16.  
  17.     if(d<a) {
  18.         // muliplier
  19.  
  20.                 // gérer les bases
  21.                 if(d == 16) reinit =3;
  22.                 else {
  23.                     if (d == 8) reinit =2;
  24.                 }
  25.                
  26.                 // débuter la programation
  27.                 nombrFinale=0;
  28.                
  29.                 poid=0;
  30.                 for(i=0; i<=sizeof(nombr) i++) {
  31.                    
  32.                     if(d != 10){if(poid == reinit) poid=0;}
  33.                    
  34.                     nombrFinale = nombrFinale + nombr[i] * (2^poid);
  35.                      poid++;
  36.                 }
  37.                
  38.                 printf("%d", nombrFinale);
  39.  
  40.        
  41.     }else {
  42.         // diviser
  43.        
  44.                 /* convertir le string en int !*/
  45.                 /* debut convertion en binaire*/
  46.                   for(i=0; nombr > 0; i++)  
  47.                       {  
  48.                         tab[i] = nombr%2;  
  49.                         nombr = nombr/2;  
  50.                       }
  51.                  
  52.                   printf("\nLe nombre binaire est = ");
  53.                  
  54.                   for(i=i-1; i >= 0; i--)  
  55.                       {  
  56.                         printf("%d",tab[i]);  
  57.                       }  
  58.                 /* fin convertion en binaire*/
  59.  
  60.     }
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement