Advertisement
adnanj

Pretvaranje iz decimalnog u binarni brojni sistem

Dec 6th, 2013
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int getBinarni(int);
  5.  
  6. int main() {
  7.  
  8.     int broj;
  9.  
  10.     cout << "Unesite broj u decimalnom zapisu: ";
  11.     cin >> broj;
  12.  
  13.     cout << "Binarni ekvivalent unesenog broja je " << getBinarni(broj) << ".";
  14.  
  15.     system("pause>0");
  16.     return 0;
  17. }
  18.  
  19. int getBinarni(int broj) {
  20.     int bin = 0;
  21.     while (broj)
  22.     {
  23.         bin = bin * 10 + broj % 2;
  24.         broj /= 2;
  25.     }
  26.     return bin;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement