Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- bool prva_cifra(int broj) {
- int novi_broj = 0, cifra = 0;
- while (broj != 0) {
- cifra = broj % 10;
- novi_broj = novi_broj * 10 + cifra;
- broj /= 10;
- }
- int cifra1 = novi_broj % 10;
- if (cifra1 % 2 == 0)
- return true;
- else
- return false;
- }
- void ispis(int niz[]) {
- for (int i = 0; i < 10; i++)
- cout << niz[i] << " ";
- }
- bool prost(int broj) {
- int brojac = 0;
- for (int i = 1; i <= broj; i++)
- if (broj%i == 0)
- brojac++;
- if (brojac == 2)
- return true;
- else
- return false;
- }
- bool jedna_parna_cifra(int broj) {
- int cifra = 0, brojac = 0;
- while (broj != 0) {
- cifra = broj % 10;
- if (cifra % 2 == 0)
- brojac++;
- broj /= 10;
- }
- if (brojac == 1)
- return true;
- else
- return false;
- }
- void sort(int niz[],int n) {
- bool promjena = true;
- while (promjena) {
- promjena = false;
- for (int i = 0; i < n-1; i++)
- {
- if (niz[i] > niz[i + 1]) {
- int temp = niz[i];
- niz[i] = niz[i + 1];
- niz[i + 1] = temp;
- promjena = true;
- }
- }
- }
- }
- int main() {
- const int vel = 10;
- int niz[vel];
- for (int i = 0; i < 10; i++)
- {
- cout << "Unesi " << i + 1 << ". clan niza: ";
- cin >> niz[i];
- if (niz[i] == 0) {
- cout << "Forsiran prekid!!!" << endl;
- break;
- system("pause>0");
- return 0;
- }
- if (prva_cifra(niz[i]) != true) {
- cout << "Pogresan unos. Ponovi unos " << i + 1 << ". clana niza: ";
- cin >> niz[i];
- }
- if (niz[i] < 0) {
- cout << "Pogresan unos. Ponovi unos " << i + 1 << ". clana niza: ";
- cin >> niz[i];
- }
- if (niz[i] % 2 == 0) {
- cout << "Pogresan unos. Ponovi unos " << i + 1 << ". clana niza: ";
- cin >> niz[i];
- }
- }
- cout << endl << endl;
- cout << "Niz nakon unosa clanova: ";
- ispis(niz);
- for (int i = 0; i < 10; i++)
- if (prost(niz[i]) == false && jedna_parna_cifra(niz[i]) == true)
- niz[i] = 0;
- cout << endl << endl;
- cout << "Niz nakon uklanjanja clanova: ";
- ispis(niz);
- cout << endl << endl;
- cout << "Sortirani niz: ";
- sort(niz, vel);
- ispis(niz);
- system("pause>0");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement