hurmawe

8.5

May 19th, 2022 (edited)
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. int sum(int lenght)
  6. {
  7.     int result = 0;
  8.     for (int i = 1; i <= lenght; i++)
  9.         result += i;
  10.     return result;
  11. }
  12. int main()
  13. {
  14. int lenght;
  15. cout << "Задание 1" << endl<< "Введите число " << endl;
  16.     cin >> lenght;
  17.     cout << "Сумма чисел от 1 до " << lenght << " = " << sum(lenght) << endl;
  18. }
Add Comment
Please, Sign In to add comment