adnanj

Suma članova niza s neparnim indeksom

Dec 25th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void Unos(float [], int);
  5. float Suma(float [], int);
  6.  
  7. int main() {
  8.         const int v = 6;
  9.     float niz[v];
  10.  
  11.     Unos(niz, v);
  12.  
  13.     cout << "Suma elemenata s neparnim indeksom iznosi: " << Suma(niz, v) << ".";
  14.  
  15.     system("pause>0");
  16.     return 0;
  17. }
  18.  
  19. void Unos(float niz[], int v) {
  20.     for(int i = 0; i < v; i++) {
  21.     cout << "Unesite [" << i << "] element niza: ";
  22.     cin >> niz[i];
  23.     }
  24. }
  25.  
  26. float Suma(float niz[], int v) {
  27.     int suma = 0;
  28.     for(int i = 1; i < v; i += 2) {
  29.     suma += niz[i];
  30.     }
  31.     return suma;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment