Last active
August 29, 2015 14:23
-
-
Save AgrYpn1a/885b0f449998ef514122 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Napisati program koji ucitava prirodan borj N, a zatim izracunava i stampa | |
drugu cifru (c), sa leve strane broja N, koja je veca od 3. Ukoliko N nema | |
dve cifre koje su vece od 3 ispisati odgovarajucu poruku. Primer, ako je N = 7326, C = 6 | |
*/ | |
#include <iostream> | |
#include <stdio.h> | |
using namespace std; | |
int izbroj_cifre(int broj); | |
void uzmi_cifre(int broj, int* cifre); | |
int vrati_uslov(int broj, int* cifre); | |
int divlji(int broj); | |
int main() { | |
int broj, moja_cifra; | |
scanf("%d", &broj); | |
int cifre[izbroj_cifre(broj)]; | |
uzmi_cifre(broj, cifre); | |
moja_cifra = vrati_uslov(broj, cifre); | |
if (moja_cifra > 3) | |
printf("%d", moja_cifra); | |
else | |
printf("Nisam nasao cifru"); | |
return 0; | |
} | |
int vrati_uslov(int broj, int* cifre) { | |
int i, length, redcif = 0; | |
length = izbroj_cifre(broj); | |
for(i=0; i<length; i++) { | |
if(cifre[i] > 3) { | |
if (redcif > 0) | |
return cifre[i]; | |
redcif++; | |
} | |
} | |
return 0; | |
} | |
int izbroj_cifre(int broj) { | |
int br_cifara; | |
while(broj != 0) { | |
broj /= 10; | |
++br_cifara; | |
} | |
return br_cifara; | |
} | |
void uzmi_cifre(int broj, int* cifre) { | |
int i = 0; | |
while(broj != 0) { | |
cifre[i] = broj % 10; | |
broj /= 10; | |
i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment