Advertisement
Pashanze

Untitled

Oct 28th, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int ArrayofUnique(int* Array, int length)////////////////////function we needed to get(deleting equal members of massive)
  7. {
  8.     int j, p, n;
  9.     for (j = 0; j < length - 1; j++)
  10.         for (p = j + 1; p < length; p++)
  11.             if (Array[j] == Array[p])
  12.             {
  13.                 for (n = p; n < length; n++)
  14.                     Array[n] = Array[n + 1];
  15.                     length--;
  16.             }
  17.     int* UniqueArr = new int[length];
  18.     cout << endl << "size of new array is " << length << endl << endl << "this is new array: ";
  19.     for (j = 0; j < length; j++)
  20.     {
  21.         UniqueArr[j] = Array[j];
  22.         cout << setw(4) << UniqueArr[j];
  23.     }
  24.     cout << endl;
  25.     delete[] Array;
  26.     return *UniqueArr;
  27. }
  28.  
  29.  
  30. int getint()
  31. {
  32.     double a;
  33.     bool x = false;
  34.     cin >> a;
  35.     if (a - round(a) == 0) {
  36.  
  37.     }
  38.     if (a < 2 || a - round(a) != 0) {
  39.         x = true;
  40.     }
  41.     while (cin.fail() || x) {
  42.         cin.clear();
  43.         cin.ignore(4000, '\n');
  44.         cout << "this input is invalid, try again: ";
  45.         cin >> a;
  46.         cout << endl;
  47.         if (a - round(a) == 0) {
  48.             x = false;
  49.         }
  50.         if (a < 2 || a - round(a) != 0) {
  51.             x = true;
  52.         }
  53.     }return round(a);
  54. }
  55.  
  56.  
  57. int main()
  58. {
  59.    
  60.     int length;
  61.  
  62.     ///////////genering an array of integers and use our function
  63.  
  64.     cout << "length of array: ";
  65.     length = getint();
  66.  
  67.     int* Array = new int[length];
  68.  
  69.     for (int i = 0; i < length; i++)
  70.     {
  71.         cout << "enter element A[" << i << "]:";
  72.         Array[i] = getint();
  73.     }
  74.     cout << endl << "this is start array: ";
  75.     for (int i = 0; i < length; i++)
  76.     {
  77.         cout << setw(4) << Array[i];
  78.     }
  79.     cout << endl;
  80.  
  81.     ArrayofUnique(Array, length);
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement