Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- int f(int M, int N)
- {
- int sum = 0;
- for (int i = M; i <= N; i++)
- {
- if (i % 2 == 1)
- sum += i;
- }
- return sum;
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- int M, N;
- cout << "Введите число M: ";
- cin >> M;
- cout << "Введите число N: ";
- cin >> N;
- cout << "Сумма всех нечетных целых чисел в пределах от M до N включительно: " << f(M, N) << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement