Advertisement
Guest User

Vector funct. adunare

a guest
Mar 24th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int sum ( int a[100] )
  5. {
  6. int n;
  7. cout << "n = ";
  8. cin >> n;
  9. int i;
  10.  
  11. for ( i = 1; i <= n; i++ ) {
  12. cout << "a[" << i <<"] = ";
  13. cin >> a[i];
  14. // s = s + a[i];
  15. }
  16. int s = 0;
  17. for ( i = 1; i <= n; i++ ) {
  18. s = s + a[i];
  19. }
  20.  
  21. cout << s << " ";
  22. }
  23.  
  24. int main(){
  25.  
  26. //int n;
  27. //cout << "n = ";
  28. //cin >> n;
  29.  
  30.  
  31. int n;
  32. int a[100];
  33. cout << sum(a);
  34.  
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement