Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- const int max = 7;
- void unos(float[],int);
- int negativni(float[],int);
- float prosjekP(float[],int);
- int main()
- {
- float niz[max];
- unos(niz, max);
- float y = prosjekP(niz, max);
- int x55 = negativni(niz, max);
- cout << "\nNegativnih elemenata ima: " << x55 << endl;
- cout << "Prosjek za pozitivne elemente iznosi: " << y << endl << endl;
- return 0;
- }
- void unos(float niz[], int max)
- {
- for (int i = 0; i < max; i++)
- {
- cout << "Unesite " << i + 1 << " realni element niza: ";
- cin >> niz[i];
- }
- }
- int negativni(float niz[],int max)
- {
- int neg = 0;
- for (int i = 0; i < max; i++)
- {
- if (niz[i] < 0)
- {
- neg++;
- }
- }
- return neg;
- }
- float prosjekP(float niz[],int max)
- {
- float suma = 0;
- float br = 0;
- for (int i = 0; i < max; i++)
- {
- if (niz[i] > 0)
- {
- suma += niz[i];
- br++;
- }
- }
- return suma/br;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement