ivanakarpuzova

min cifra + rekurzija

Jan 12th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. /*
  6. Рекурзија :
  7. int minCifra(int broj,int min)
  8. {
  9.     if(broj == 0) {
  10.         return min;
  11.     }
  12.     if(min > broj%10) {
  13.         min = broj%10;
  14.     }
  15.     minCifra(broj/10, min);
  16. }
  17. */
  18. int minCifra(int broj)
  19. {
  20.     int min = 100000;
  21.     while(broj > 0) {
  22.         if(min > broj % 10) {
  23.             min = broj%10;
  24.         }
  25.         broj = broj / 10;
  26.     }
  27.     return min;
  28. }
  29. int main () {
  30.     int broj,min = 10000000;
  31.     while(scanf("%d",&broj)) {
  32.         printf("%d\n",minCifra(broj));
  33.     }
  34.  
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment