Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. bool prva_cifra(int broj) {
  5. int novi_broj = 0, cifra = 0;
  6. while (broj != 0) {
  7. cifra = broj % 10;
  8. novi_broj = novi_broj * 10 + cifra;
  9. broj /= 10;
  10. }
  11. int cifra1 = novi_broj % 10;
  12. if (cifra1 % 2 == 0)
  13. return true;
  14. else
  15. return false;
  16. }
  17.  
  18. void ispis(int niz[]) {
  19. for (int i = 0; i < 10; i++)
  20. cout << niz[i] << " ";
  21. }
  22.  
  23. bool prost(int broj) {
  24. int brojac = 0;
  25. for (int i = 1; i <= broj; i++)
  26. if (broj%i == 0)
  27. brojac++;
  28. if (brojac == 2)
  29. return true;
  30. else
  31. return false;
  32. }
  33.  
  34. bool jedna_parna_cifra(int broj) {
  35. int cifra = 0, brojac = 0;
  36. while (broj != 0) {
  37. cifra = broj % 10;
  38. if (cifra % 2 == 0)
  39. brojac++;
  40. broj /= 10;
  41. }
  42. if (brojac == 1)
  43. return true;
  44. else
  45. return false;
  46. }
  47.  
  48. void sort(int niz[],int n) {
  49. bool promjena = true;
  50. while (promjena) {
  51. promjena = false;
  52. for (int i = 0; i < n-1; i++)
  53. {
  54. if (niz[i] > niz[i + 1]) {
  55. int temp = niz[i];
  56. niz[i] = niz[i + 1];
  57. niz[i + 1] = temp;
  58. promjena = true;
  59. }
  60. }
  61. }
  62. }
  63.  
  64. int main() {
  65. const int vel = 10;
  66. int niz[vel];
  67. for (int i = 0; i < 10; i++)
  68. {
  69. cout << "Unesi " << i + 1 << ". clan niza: ";
  70. cin >> niz[i];
  71.  
  72. if (niz[i] == 0) {
  73. cout << "Forsiran prekid!!!" << endl;
  74. break;
  75. system("pause>0");
  76. return 0;
  77. }
  78. if (prva_cifra(niz[i]) != true) {
  79. cout << "Pogresan unos. Ponovi unos " << i + 1 << ". clana niza: ";
  80. cin >> niz[i];
  81. }
  82. if (niz[i] < 0) {
  83. cout << "Pogresan unos. Ponovi unos " << i + 1 << ". clana niza: ";
  84. cin >> niz[i];
  85. }
  86. if (niz[i] % 2 == 0) {
  87. cout << "Pogresan unos. Ponovi unos " << i + 1 << ". clana niza: ";
  88. cin >> niz[i];
  89. }
  90. }
  91. cout << endl << endl;
  92.  
  93. cout << "Niz nakon unosa clanova: ";
  94. ispis(niz);
  95.  
  96. for (int i = 0; i < 10; i++)
  97. if (prost(niz[i]) == false && jedna_parna_cifra(niz[i]) == true)
  98. niz[i] = 0;
  99.  
  100. cout << endl << endl;
  101.  
  102. cout << "Niz nakon uklanjanja clanova: ";
  103. ispis(niz);
  104.  
  105. cout << endl << endl;
  106.  
  107. cout << "Sortirani niz: ";
  108. sort(niz, vel);
  109. ispis(niz);
  110.  
  111. system("pause>0");
  112. return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement