Advertisement
sellmmaahh

OR-Vrati Najveci Broj

Sep 6th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int length (char *s) {
  6.     int d=0;
  7.     while (*(s++)!='\0') d++;
  8.     return d;
  9. }
  10. int JeLiBroj (char c) {
  11.     if (c>='0' && c<='9') return 1;
  12.     return 0;
  13. }
  14. int MaxBroj (char *s) {
  15.     int duzina=length(s), i, nb=0, max_broj=0;
  16.     for (i=0; i<duzina; i++) {
  17.             if (JeLiBroj(s[i])) {
  18.                     nb=nb*10+s[i]-'0';
  19.                     i++;
  20.                     while (JeLiBroj(s[i])) {
  21.                             nb=nb*10+s[i]-'0';
  22.                             i++;
  23.                     }
  24.             }
  25.             if (nb>max_broj)
  26.                    max_broj=nb;
  27.             else nb=0;
  28.     }
  29.     return max_broj;
  30. }
  31.  
  32. int main () {
  33.     char s[]="Selma234 je bila 5678 ovdje 123.";
  34.     printf("Najveci broj u recenici: %d", MaxBroj(s));
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement