Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. struct minmax
  7. {
  8. int min;
  9. int max;
  10. };
  11.  
  12. minmax sum(int [], int);
  13.  
  14. minmax sum(int *table, int size)
  15. {
  16. minmax result;
  17. int max, min;
  18. float sr=0;
  19.  
  20. min = max = table[0];
  21. for(int i = 0; i < size; i++)
  22. {
  23. if(table[i] > max)
  24. {
  25. max = table[i];
  26. }
  27. if(table[i] < min)
  28. {
  29. min = table[i];
  30. }
  31. sr =sr + table[i];
  32. }
  33. sr=sr/size;
  34.  
  35. result.min = min;
  36. result.max = max;
  37. return result;
  38.  
  39. }
  40.  
  41. int main()
  42. {
  43.  
  44.  
  45. int n=0;
  46. int *tab;
  47. cout<<"Podaj dlugosc ciagu: ";
  48. cin>> n;
  49. tab=new int[n];
  50. for(int i=0;i<n;i++)
  51. {
  52. int ilosc=0;
  53. cout<<"Podaj element "<<i+1<<" : ";
  54. cin>>tab[i];
  55.  
  56. }
  57.  
  58. sum(tab, n);
  59. minmax wynik;
  60. cout<< wynik.min;
  61.  
  62.  
  63.  
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement