Advertisement
Josif_tepe

Untitled

May 27th, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int najgolema_cifra(int broj) {
  5.     if(broj == 0) {
  6.         return 0;
  7.     }
  8.     int cifra = broj % 10;
  9.     int naj_cifra = najgolema_cifra(broj / 10);
  10.     if(cifra > naj_cifra) {
  11.         return cifra;
  12.     }
  13.     else {
  14.         return naj_cifra;
  15.     }
  16. }
  17. // najgolema_cifra(123) = maksimum ( najgolema_cifra(12), 3) = (2, 3) = 3
  18. // najgolema_cifra(12) = maksimum ( najgolema_cifra(1), 2) = (1, 2) = 2
  19. // najgolema_cifra(1) = maksimum( najgolema_cifra(0) , 1) = (0, 1) = 1
  20. // najgolema_cifra(0) = 0
  21.  
  22. int main() {
  23.     int n;
  24.     while (scanf("%d", &n)) {
  25.         printf("%d\n", najgolema_cifra(n));
  26.     }
  27.     return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement