Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int max(int a, int b){
- if(a>b)
- return a;
- else
- return b;
- }
- int rekurzija(int broj){
- if(broj < 10) { // ednocifren broj
- return broj;
- }
- else {
- int posledna_cifra = broj % 10; // posledna cifra od brojot
- return max(rekurzija(broj / 10), posledna_cifra);
- }
- }
- int main()
- {
- int broj;
- while(scanf("%d", &broj)){
- printf("%d\n", rekurzija(broj));
- }
- return 0;
- }
- // rekurzija(125612) = max(6, 2) = 6
- // rekurzija(12561) = max(6, 1) = 6
- // rekurzija(1256) = max(5, 6) = 6
- //rekurzija(125) = max(2, 5) = 5
- //rekurzija(12) = max(1, 2) = 2
- //rekurzija(1) = 1
Advertisement
Add Comment
Please, Sign In to add comment