andrelievable

agg

Dec 7th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3. using namespace std;
  4.  
  5. void tablica(int *arr)
  6. {
  7.     int i;
  8.     for(i=0; i<10;i++)
  9.     {
  10.     cout<<arr[i]<<" ";
  11.     }
  12.     cout<<endl;
  13. }
  14.  
  15. int func(int *arr)
  16. {
  17.     int j, agreg;
  18.     for(j=0;j<10;j++)
  19.     {
  20.         agreg+=arr[j];
  21.     }
  22.    
  23.  
  24.     return agreg;
  25. }
  26. typedef int(*f)(int*);
  27.  
  28. void agg(f func, int *arr)
  29. {
  30.     cout<<"suma tablicy"<<func(arr)<<endl;
  31.    
  32. }
  33.  
  34. void agg2(function <int(int *)>func, int *arr)
  35. {
  36.     cout<<"suma tablicy: "<<func(arr)<<endl;
  37.    
  38. }
  39.  
  40. int main()
  41. {
  42.     int tab[10]={1,2,3,4,5,6,7,8,9,0};
  43.     tablica(tab);
  44.     agg(func, tab);
  45.     agg2(func, tab);
  46.    
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment