Advertisement
Serafim_

Сумма элементов массива

Oct 11th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using std::cout;
  5. using std::cin;
  6. using std::endl;
  7.  
  8. int main()
  9. {
  10.     int n;
  11.     cout << "Введите количество элементов массива : ";
  12.     cin >> n  ;
  13.  
  14.         int a[n];int l;int b;
  15.  
  16.         // Заполняем массив с клавиатуры
  17.         for (int i = 0; i < n; i++) {
  18.             cout << "[" << i + 1 << "]" << ": ";
  19.             cin >> a[i];
  20.         }
  21.  
  22.  
  23.         cout << "\Сумма элементов массива: ";
  24.  
  25.         for (int i = 0; i < n; ++i) {
  26.            l=a[i]+l;
  27.         }
  28.  
  29. cout<<l<<endl;
  30.         return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement