Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int okreni(int n)
- {
- int broj = 0;
- while(n > 0)
- {
- broj = broj * 10 + n % 10;
- n = n / 10;
- }
- return broj;
- }
- int suma_brojeva_lijevo(char* string)
- {
- int broj = 0, suma = 0;
- while(*string != 0)
- {
- if (*string >= '0' && *string <= '9')
- {
- broj = broj * 10 + (*string - '0');
- } else
- {
- suma += broj;
- broj = 0;
- }
- string++;
- }
- if (broj != 0) suma += broj;
- return suma;
- }
- int suma_brojeva_desno(char* string)
- {
- int broj = 0, suma = 0;
- while(*string != 0)
- {
- if (*string >= '0' && *string <= '9')
- {
- broj = broj * 10 + (*string - '0');
- } else
- {
- suma += okreni(broj);
- broj = 0;
- }
- string++;
- }
- if (broj != 0) suma += okreni(broj);
- return suma;
- }
- int main()
- {
- char string[] = "hrk13ljus13";
- printf("%d\n", suma_brojeva_lijevo(string));
- printf("%d\n", suma_brojeva_desno(string));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement