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