fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. long double moc(int liczba, int potega)
  8. {
  9. long double wynik = 1;
  10. while(potega--)
  11. wynik *= liczba;
  12. return wynik;
  13. }
  14. int dlugosc(long double in)
  15. {
  16. int dlg = 0;
  17. for (; in > 3; dlg++)
  18. in /= 10;
  19. return dlg;
  20. }
  21. void to_bin(int input, long double & output)
  22. {
  23. if (input > 1)
  24. to_bin(input/2, output);
  25. output*= 10;
  26. output+= (int)(input % 2)+1;
  27. }
  28. void to_tab(long double input, bool tab[], int cg)
  29. {
  30. cout << input << "\n";
  31. while (input >= 1)
  32. {
  33. int d = dlugosc(input);
  34. tab[cg] = (floor( input / moc(10, d) - 1 ));
  35.  
  36. input/= moc(10, d);
  37. input-= floor(input);
  38. input*= moc(10, d);
  39. cout << tab[cg];
  40. cg++;
  41. }
  42. }
  43. int main()
  44. {
  45. cout << fixed << setprecision(0);
  46. long double m = 0; // glowna
  47. long double c = 0; // potega
  48. long double p = 0; // przecinek
  49. int d;
  50. int cg = 1;
  51. float in;
  52. bool minus = false;
  53. bool tablica[32] = {0};
  54.  
  55. cin >> in;
  56. if (in < 0) minus = true, in *= -1;
  57. to_bin(in, m);
  58. d = dlugosc(m);
  59. to_bin(d+127, c);
  60.  
  61. m /= moc(10, d);
  62. m -= int(m);
  63. m *= moc(10, d);
  64. to_tab(m, tablica, cg);
  65. }
Success #stdin #stdout 0.01s 2728KB
stdin
Standard input is empty
stdout
0