Advertisement
heian

Untitled

Oct 24th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. /**
  6. Se da un vector de numere reale si un numar natural k.
  7. Sa se returneze suma numerelor vi din vector cu propr ca i<k.
  8.  
  9. Sa se foloseasca un subprogram.
  10. */
  11.  
  12. float sum(float v[], int k)
  13. {
  14. int s;
  15. s=0;
  16. for(i=1;i<=k;i++)
  17. s+=v[i];
  18. return s;
  19. }
  20.  
  21.  
  22. int main()
  23. {
  24. float a[51];
  25.  
  26. ///citirea
  27. int i,k;
  28. cin>>k;
  29. for(i=1;i<=50;i++)
  30. cin>>a[i];
  31.  
  32. ///calcularea sumei
  33. cout<<sum(a, k);
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement