amermo

da li broj ima istih cifara - preko nizova

Feb 27th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. bool iste_cifre(int broj)
  4. {
  5.     int niz_brojaca[50] = {0};
  6.     int a(broj);
  7.     while(a > 0)
  8.     {
  9.         niz_brojaca[a%10]++;
  10.         a/=10;
  11.     }
  12.     for(int i(0); i < 50; i++)
  13.     {
  14.         if(niz_brojaca[i] > 1)
  15.             return true;
  16.     }
  17.     return false;
  18. }
  19.  
  20.  
  21. int main()
  22. {
  23.     int n;
  24.     std::cout << "Unesite neki broj: " << std::endl;
  25.     std::cin >> n;
  26.     if(iste_cifre(n))
  27.         std::cout << "Broj ima istih cifara!" << std::endl;
  28.     else
  29.         std::cout << "Broj nema istih cifara!" << std::endl;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment