Advertisement
sellmmaahh

OR-skriptica zad6-sv br u stringu

Aug 16th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. float SrednjaVrijednost (char *s)
  5. { int suma=0, br_broj=0;
  6. int nb=0;
  7. while (*s!='\0')
  8. {
  9.     if (*s>='0' && *s<='9') {
  10.     while (*s>='0' && *s<='9') {
  11.         nb=nb*10+(*s-'0');
  12.         s++;
  13.     }
  14.     if (nb>0) {
  15.         br_broj++;
  16.     suma+=nb;
  17.     }
  18.     nb=0;
  19.     }
  20.     else s++;
  21. }
  22. return suma/br_broj;
  23. }
  24.  
  25.  
  26. int main () {
  27.     char s[]="Fakultet je upisalo 225 redovnih, 83 vandredna i 4 studenta strana drzavljana.";
  28.     printf("%.2f",SrednjaVrijednost(s));
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement