monito2207

d1_5

Oct 31st, 2021 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. /**
  2. *
  3. * Solution to homework assignment 1
  4. * Introduction to programming course
  5. * Faculty of Mathematics and Informatics of Sofia University
  6. * Winter semester 2021/2022
  7. *
  8. * @author Monika Dobrinova
  9. * @idnumber 8MI0600008
  10. * @task 5
  11. * @compiler VC
  12. *
  13. */
  14.  
  15. #include <iostream>
  16. using namespace std;
  17. int main()
  18. {
  19.     long long int n;
  20.     cin >> n;
  21.     long long int temp = n;
  22.     int count = 0;
  23.  
  24.     while (temp)
  25.     {
  26.         temp /= 10;
  27.         count++;
  28.     }
  29.  
  30.     long long int pow = 1, num = 0;
  31.  
  32.  
  33.     for (int i = 1; i < count; i++)
  34.     {
  35.         pow *= 10;
  36.     }
  37.      short int counter2=0;
  38.         while (n)
  39.         {
  40.             num = n / pow;
  41.  
  42.             if (num % 2 != 0)
  43.             {
  44.                 cout << num << " ";
  45.             }
  46.             else
  47.             {
  48.                 counter2++;
  49.             }
  50.        
  51.  
  52.             n %= pow;
  53.             pow /= 10;
  54.         }
  55.         if (count == counter2)
  56.         {
  57.             cout << "0";
  58.         }
  59.         cout << endl;
  60.         return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment