B1LLy

#8 programowanie - lab

Dec 2nd, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. Zamiana na forme binarna części po przecinku. - DO DOMU
  2. -------------------------------------------------------------
  3.  
  4. ZADANIE Z ZAJĘĆ - ZAMIANA LICZBY DIESIETNEJ NA BINARNĄ
  5.  
  6. #include "stdafx.h"
  7. #include <iostream>
  8.  
  9. using namespace std;
  10. void do_binar(unsigned long n);
  11.  
  12. using namespace std;
  13.  
  14. int main(void)
  15. {
  16. unsigned long liczba;
  17. printf("podaj liczbe calkowita \n");
  18. while (scanf_s("%ld", &liczba) == 1)
  19. {
  20. printf("odpowiednik dwojkowy: ");
  21. do_binar(liczba);
  22. putchar(' \n');
  23. printf("podaj liczbe calkowita \n");
  24. }
  25. printf("gotowe \n");
  26. return 0;
  27. }
  28. void do_binar(unsigned long n) //funkcja rekurencyjna
  29. {
  30. int r;
  31. r = n % 2;
  32. if (n >= 2)
  33. do_binar(n / 2);
  34. putchar(r == 0 ? '0' : '1');
  35.  
  36. return;
  37. }
  38.  
  39. ------------------------------------------------------------------------------------------
  40. ZADANIE Z ZAJĘĆ - ^ TO SAMO, ALE Z TABLICAMI
  41.  
  42. #include "stdafx.h"
  43. #include <iostream>
  44.  
  45. using namespace std;
  46.  
  47. void do_binar(int i, int tab[16]);
  48. int z2na10(int tab[16]);
  49.  
  50. int main()
  51. {
  52. int ii, iin, ilicz, itab[16], ii2;
  53.  
  54. cout << " podaj liczbe typu int: ";
  55. cin >> ii;
  56. do_binar(ii, itab);
  57. cout << " reprezentacja binarna: " << endl;
  58. //
  59. for (ilicz = 15; ilicz >= 0; ilicz--)
  60. {
  61. iin = itab[ilicz];
  62. cout << " " << iin;
  63. if (ilicz == 8)
  64. cout << " ";
  65. }
  66. cout << endl;
  67.  
  68. getchar();
  69. getchar();
  70. return 0;
  71. }
  72. void do_binar(int i, int tab[16])
  73. {
  74. int ilicz, irob;
  75. irob = i;
  76. for (ilicz = 0; ilicz <= 15; ilicz++)
  77. {
  78. tab[ilicz] = irob % 2;
  79. irob /= 2;
  80. }
  81. }
  82.  
  83. -------------------------------------------------------------------------
  84.  
  85. ZADANIE Z ZAJĘĆ - ^ z powrotem
Add Comment
Please, Sign In to add comment