Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Zamiana na forme binarna części po przecinku. - DO DOMU
- -------------------------------------------------------------
- ZADANIE Z ZAJĘĆ - ZAMIANA LICZBY DIESIETNEJ NA BINARNĄ
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- void do_binar(unsigned long n);
- using namespace std;
- int main(void)
- {
- unsigned long liczba;
- printf("podaj liczbe calkowita \n");
- while (scanf_s("%ld", &liczba) == 1)
- {
- printf("odpowiednik dwojkowy: ");
- do_binar(liczba);
- putchar(' \n');
- printf("podaj liczbe calkowita \n");
- }
- printf("gotowe \n");
- return 0;
- }
- void do_binar(unsigned long n) //funkcja rekurencyjna
- {
- int r;
- r = n % 2;
- if (n >= 2)
- do_binar(n / 2);
- putchar(r == 0 ? '0' : '1');
- return;
- }
- ------------------------------------------------------------------------------------------
- ZADANIE Z ZAJĘĆ - ^ TO SAMO, ALE Z TABLICAMI
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- void do_binar(int i, int tab[16]);
- int z2na10(int tab[16]);
- int main()
- {
- int ii, iin, ilicz, itab[16], ii2;
- cout << " podaj liczbe typu int: ";
- cin >> ii;
- do_binar(ii, itab);
- cout << " reprezentacja binarna: " << endl;
- //
- for (ilicz = 15; ilicz >= 0; ilicz--)
- {
- iin = itab[ilicz];
- cout << " " << iin;
- if (ilicz == 8)
- cout << " ";
- }
- cout << endl;
- getchar();
- getchar();
- return 0;
- }
- void do_binar(int i, int tab[16])
- {
- int ilicz, irob;
- irob = i;
- for (ilicz = 0; ilicz <= 15; ilicz++)
- {
- tab[ilicz] = irob % 2;
- irob /= 2;
- }
- }
- -------------------------------------------------------------------------
- ZADANIE Z ZAJĘĆ - ^ z powrotem
Add Comment
Please, Sign In to add comment