Advertisement
sellmmaahh

OR-Rjesenja Nekih Zadataka-zad1

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