josiftepe

Untitled

Dec 25th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int max(int a, int b){
  5.     if(a>b)
  6.         return a;
  7.     else
  8.         return b;
  9. }
  10. int rekurzija(int broj){
  11.     if(broj < 10) { // ednocifren broj
  12.         return broj;
  13.     }
  14.     else {
  15.         int posledna_cifra = broj % 10; // posledna cifra od brojot
  16.         return max(rekurzija(broj / 10), posledna_cifra);
  17.     }
  18. }
  19.  
  20. int main()
  21. {
  22.     int broj;
  23.     while(scanf("%d", &broj)){
  24.         printf("%d\n", rekurzija(broj));
  25.     }
  26.     return 0;
  27. }
  28. // rekurzija(125612) = max(6, 2) = 6
  29. // rekurzija(12561) = max(6, 1) = 6
  30. // rekurzija(1256) = max(5, 6) = 6
  31. //rekurzija(125) = max(2, 5) = 5
  32. //rekurzija(12) = max(1, 2) = 2
  33. //rekurzija(1) = 1
  34.  
Advertisement
Add Comment
Please, Sign In to add comment