Advertisement
Ancutahij

Problema_recursiva_cifre

Mar 13th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. //#pragma warning(disable: 4996)
  6. void citire(int &n)
  7. {
  8.    
  9.     cin >> n;
  10.     if (n <= 0)
  11.         citire(n);
  12.  
  13. }
  14.  
  15. int cauta_val_existenta(int sir[], int val, int lung)//consideram sirul crescator
  16. {
  17.     if (lung > 0 && val != sir[lung])
  18.         return cauta_val_existenta(sir, val, lung - 1);
  19.  
  20.     if (lung == 0)
  21.         return false;
  22.     else
  23.         return true;
  24. }
  25.  
  26. void inserare_element_cresc(int sir[], int lung, int k)
  27. {
  28.     if (lung > 0 && k < sir[lung])
  29.     {
  30.         sir[lung + 1] = sir[lung];
  31.         inserare_element_cresc(sir, lung - 1, k);
  32.     }
  33.     else
  34.         sir[lung + 1] = k;
  35. }
  36.  
  37.  
  38.  
  39. void creare_multime(int multime[], int n, int &lung)
  40. {
  41.     if (n > 0)
  42.     {
  43.         if (cauta_val_existenta(multime, n % 10, lung) == 0)
  44.         {
  45.             inserare_element_cresc(multime, lung, n % 10);
  46.             lung++;
  47.         }
  48.         creare_multime(multime, n / 10, lung );
  49.     }
  50. }
  51.  
  52. void afisare(int multime[], int lung)
  53. {
  54.     if (lung > 0)
  55.     {
  56.         afisare(multime, lung - 1);
  57.         cout << multime[lung] << "   ";
  58.     }
  59.     else
  60.         cout << "multimea n:";
  61. }
  62. int main()
  63. {
  64.     int n, multime[10], lung = 0;
  65.     citire(n);
  66.     creare_multime(multime, n, lung);
  67.     afisare(multime, lung);
  68.     cout << endl << endl;
  69.     system("pause");
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement