Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int *avtomorf(int *array, int n)
  7. {
  8. bool *check = new bool[n];
  9. int amount = 0;
  10. for (int i = 0; i<n; i++)
  11. {
  12. int del = 1;
  13. while (array[i] / del != 0)
  14. {
  15. del *= 10;
  16. }
  17. if ((array[i] * array[i] - array[i]) % del == 0) {
  18. check[i] = true;
  19. ++amount;
  20. cout << amount << endl;
  21. }
  22. else {
  23. check[i] = false;
  24. }
  25. }
  26. // Вводим их в массив
  27. int *result = new int[amount];
  28. int j = 0;
  29. for (int i = 0; i < n; i++)
  30. {
  31. if (check[i]) {
  32. result[j] = array[i];
  33. ++j;
  34. }
  35. }
  36. sort(result, result + amount);
  37. for (int i = 0; i < amount; i++)
  38. cout << result[i] << ' ';
  39. return result;
  40. }
  41.  
  42. int main()
  43. {
  44. const int n = 10;
  45. int mas[n] = { 1,5,36,9,35,8,625,10,3,376 };
  46. int *a = avtomorf(mas, n);
  47.  
  48. if (a != NULL)
  49. delete[]a;
  50. system("pause");
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement