Advertisement
sellmmaahh

OR-vrati max br iz stringa (i za negativne)

Aug 14th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int MaxBroj (char *s) {
  5.     int broj=0, max_broj=-1000;
  6.     char *poc=s, *p_broja;
  7.     while (*s!='\0') {
  8.                     if (*s>='0' && *s<='9') {
  9.                         p_broja=s;
  10.  
  11.                         while (*s>='0' && *s<='9')  {
  12.                         broj=broj*10+(*s-'0');
  13.                         s++;
  14.                     }
  15.                     if (*(p_broja-1)=='-') broj*=-1;
  16.  
  17.                     if (broj>max_broj) max_broj=broj;
  18.                     broj=0;
  19.             }
  20.             s++;
  21.     }
  22.     return max_broj;
  23. }
  24.  
  25.  
  26.  
  27.  
  28. int main () {
  29.     char s[]="Ovo j-2e re-23cen-456ica";
  30.  
  31.     printf("%d",MaxBroj(s));
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement