Advertisement
rusmirhockic

1D prosjekP, negativni

Jan 22nd, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. const int max = 7;
  7.  
  8. void unos(float[],int);
  9. int negativni(float[],int);
  10. float prosjekP(float[],int);
  11.  
  12. int main()
  13. {
  14. float niz[max];
  15.  
  16. unos(niz, max);
  17. float y = prosjekP(niz, max);
  18. int x55 = negativni(niz, max);
  19.  
  20. cout << "\nNegativnih elemenata ima: " << x55 << endl;
  21. cout << "Prosjek za pozitivne elemente iznosi: " << y << endl << endl;
  22.  
  23.  
  24. return 0;
  25. }
  26. void unos(float niz[], int max)
  27. {
  28. for (int i = 0; i < max; i++)
  29. {
  30. cout << "Unesite " << i + 1 << " realni element niza: ";
  31. cin >> niz[i];
  32. }
  33. }
  34. int negativni(float niz[],int max)
  35. {
  36. int neg = 0;
  37. for (int i = 0; i < max; i++)
  38. {
  39. if (niz[i] < 0)
  40. {
  41. neg++;
  42. }
  43. }
  44. return neg;
  45. }
  46. float prosjekP(float niz[],int max)
  47. {
  48. float suma = 0;
  49. float br = 0;
  50. for (int i = 0; i < max; i++)
  51. {
  52. if (niz[i] > 0)
  53. {
  54. suma += niz[i];
  55. br++;
  56. }
  57. }
  58. return suma/br;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement