Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- using namespace std;
- int sum(int lenght)
- {
- int result = 0;
- for (int i = 1; i <= lenght; i++)
- result += i;
- return result;
- }
- int main()
- {
- int lenght;
- cout << "Задание 1" << endl<< "Введите число " << endl;
- cin >> lenght;
- cout << "Сумма чисел от 1 до " << lenght << " = " << sum(lenght) << endl;
- }
Add Comment
Please, Sign In to add comment