Advertisement
Mentosan

Extraction Number Units

Sep 27th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int cate_cifre(int n);
  5. void AfisareCifre(int n, int cifre);
  6.  
  7. int main() {
  8.     int n, cateCifre;
  9.     cout << "N=";   cin >>n;
  10.     cateCifre = cate_cifre(n);
  11.  
  12.     switch(cateCifre) {
  13.         case 1: {
  14.             cout << n << endl;;
  15.             break;
  16.         }
  17.         case 2: {
  18.             cout << "- Cifra unitatilor: " << n % 10 << endl;
  19.             n /= 10;
  20.             cout << "- Cifra zecilor: " << n << endl;
  21.             break;
  22.         }
  23.         case 3: {
  24.             cout << "- Cifra unitatilor: " << n % 10 << endl;
  25.             cout << "- Cifra zecilor: " << (n / 10) % 10 << endl;
  26.             cout << "- Cifra sutelor: " << n / 100 << endl;
  27.             break;
  28.         }
  29.         case 4: {
  30.             cout << "- Cifra unitatilor: " << n % 10 << endl;
  31.             cout << "- Cifra zecilor: " << (n / 10) % 10 << endl;
  32.             cout << "- Cifra sutelor: " << (n / 100) % 10 << endl;
  33.             cout << "- Cifra miilor: " << n / 1000 << endl;
  34.             break;
  35.         }
  36.         case 5: {
  37.             cout << "- Cifra unitatilor: " << n % 10 << endl;
  38.             cout << "- Cifra zecilor: " << (n / 10) % 10 << endl;
  39.             cout << "- Cifra sutelor: " << (n / 100) % 10 << endl;
  40.             cout << "- Cifra miilor - unitati: " << (n / 1000) % 10 << endl;
  41.             cout << "- Cifra miilor - zeci: " << n / 10000 << endl;
  42.             break;
  43.         }
  44.         case 6: {
  45.             cout << "- Cifra unitatilor: " << n % 10 << endl;
  46.             cout << "- Cifra zecilor: " << (n / 10) % 10 << endl;
  47.             cout << "- Cifra sutelor: " << (n / 100) % 10 << endl;
  48.             cout << "- Cifra miilor - unitati: " << (n / 1000) % 10 << endl;
  49.             cout << "- Cifra miilor - zeci: " << (n / 10000) % 10 << endl;
  50.             cout << "- Cifra miilor - sutelor: " << n / 100000 << endl;
  51.             break;
  52.         }
  53.         default: AfisareCifre(n, cateCifre);
  54.     }
  55.     return 0;
  56. }
  57.  
  58. int cate_cifre(int n) {
  59.     int nr_cifre = 0, c;
  60.     while(n != 0) {
  61.         c = n % 10;
  62.         n /= 10;
  63.         nr_cifre++;
  64.     }
  65.     return nr_cifre;
  66. }
  67.  
  68. void AfisareCifre(int n, int cifre) {
  69.     int  v[101], i = 0, c;
  70.     while(n != 0) {
  71.         c = n % 10;
  72.         n /= 10;
  73.         v[i] = c;
  74.         i++;
  75.     }
  76.  
  77.     for(int j = 0; j < cifre; j++)
  78.         cout << v[j] << " ";
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement