Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool provjera(int);
- int getSrednjaCifra(int);
- int main() {
- int broj;
- do {
- cout << "Unesite prirodan broj n: ";
- cin >> broj;
- }
- while(broj <= 0);
- if(provjera(broj))
- cout << "Srednja znamenka je " << getSrednjaCifra(broj) << ".";
- else
- cout << "Uneseni broj nema srednju znamenku!";
- system("pause>0");
- return 0;
- }
- bool provjera(int broj) {
- if(broj < 1000 || broj > 9999)
- return false;
- return true;
- }
- int getSrednjaCifra(int broj) {
- int temp = broj, cifre = 0;
- while(temp) {
- temp /= 10;
- cifre++;
- }
- return int(broj / pow(10.0, cifre/2)) % 10;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement