amermo

prosjek svih cifara u nizu

Feb 19th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. float prosjek(int niz[], int vel)
  7. {
  8.     int i;
  9.     int cifra = 0;
  10.     int counter = 0, suma = 0;
  11.     for(i = 0; i<vel; i++)
  12.     {
  13.         while(niz[i] != 0)
  14.         {
  15.             cifra = niz[i] % 10;
  16.             niz[i] /= 10;
  17.             counter++;
  18.             suma+=cifra;
  19.         }
  20.     }
  21.     return (float)suma/counter;
  22. }
  23.  
  24.  
  25.  
  26.  
  27. int main()
  28. {
  29.     int niz[3] = {1, 21, 3};
  30.     printf("%.2f", prosjek(niz, 3));
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment