Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Funkcija vraca najveci broj iz stringa, radi i za negativne brojeve! */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <math.h>
- int maksi(char* string)
- {
- char* p = string;
- int max = pow(-2, 31);
- int broj;
- int minus;
- while(*p != '\0')
- {
- if(*p == '-')
- {
- minus = 1;
- p++;
- }
- if(*p >= '0' && *p <= '9')
- {
- broj = 0;
- while(*p >= '0' && *p <= '9' && *p != '\0')
- {
- broj*=10;
- broj+=(int)(*p - '0');
- p++;
- }
- if(minus == 1)
- broj*=(-1);
- if(broj > max)
- max=broj;
- }
- p++;
- minus = 0;
- }
- return max;
- }
- int main()
- {
- char string[100] = "-11111 ,,,,aaaa-1231, -111 -01";
- printf("Najveci broj je %d", maksi(string));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment