Tfe

Ongi etorri tfe-ren webgunera...

Old stuff/ecole_etude_fac_de_pau/nico/calc/binaire.cc

(Deskargatu)
#include<iostream.h>
#define MAX 100

char* conversion(int i)
{
    char* tab= new char[MAX];
    char temp;
    int cpt=0;
    while(i>1)
      {
        tab[cpt]=(i%2)+48;
	cpt++;
	i=i/2;
      }
    tab[cpt]=i+48;
    tab[cpt+1] = '\0';
    
for (i=0;i<(cpt/2)+1;i++)
{
    temp = tab[i];
    tab[i] = tab[cpt-i];
    tab[cpt-i] = temp;
}

    
    return tab+1;
}



main(){
  int f;
  cout<<"Partie entiere : ";
  cin>>f;
  float d;
  cout<<"Partie decimale (forme 0.xxxx): ";
  cin>>d;
  
  
  char* p;
  p = conversion(f);
  cout << p;
  cout<<'\n';
}