amermo

izbaci nule iz broja

Feb 27th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int izbaci_nule(int broj)
  4. {
  5.     int desetica(1), rezultat(0), mojbroj(broj);
  6.     while(mojbroj > 0)
  7.     {
  8.         int cifra(mojbroj % 10);
  9.         mojbroj/=10;
  10.         if(cifra == 0) continue;
  11.         rezultat+=cifra*desetica;
  12.         desetica*=10;
  13.     }
  14.     return rezultat;
  15. }
  16.  
  17.  
  18. int main()
  19. {
  20.     int n;
  21.     std::cout << "Unesite neki broj: " << std::endl;
  22.     std::cin >> n;
  23.     std::cout << "Modifikovan broj: " << izbaci_nule(n) << std::endl;
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment