Advertisement
dusanrs

poc_fun

Apr 28th, 2022
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef int funkcija(int*, int);
  5.  
  6. int minimum(int*, int);
  7. int maksimum(int*, int);
  8.  
  9. int sumaBezEkstrema(int*, int, funkcija*);
  10.  
  11. int main()
  12. {
  13.     int niz[50]={20, -30, 4, 15, -30, 20, 20, 5}, n=8;
  14.     int suma = sumaBezEkstrema(niz,n,minimum);
  15.  
  16.     printf("Suma: %d",suma);
  17.  
  18.     return 0;
  19. }
  20.  
  21. int minimum(int* niz, int n)
  22. {
  23.     int i, min=*niz;
  24.  
  25.     for(i=0;i<n;i++){
  26.         if(niz[i]<min) min=niz[i];
  27.     }
  28.  
  29.     return min;
  30. }
  31.  
  32. int maksimum(int* niz, int n)
  33. {
  34.     int i, max=*niz;
  35.  
  36.     for(i=0;i<n;i++){
  37.         if(niz[i]>max) max=niz[i];
  38.     }
  39.  
  40.     return max;
  41. }
  42.  
  43. int sumaBezEkstrema(int* niz, int n, funkcija* fun)
  44. {
  45.     int i, suma=0;
  46.  
  47.     for(i=0;i<n;i++){
  48.         if(niz[i]!=(*fun)(niz,n)) suma+=niz[i];
  49.     }
  50.  
  51.     return suma;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement