Advertisement
Guest User

Task

a guest
Feb 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1.  
  2. #include "pch.h"
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int f(int M, int N)
  8. {
  9.     int sum = 0;
  10.     for (int i = M; i <= N; i++)
  11.     {
  12.         if (i % 2 == 1)
  13.             sum += i;
  14.     }
  15.     return sum;
  16. }
  17.  
  18. int main()
  19. {
  20.     setlocale(LC_ALL, "rus");
  21.     int M, N;
  22.     cout << "Введите число M: ";
  23.     cin >> M;
  24.     cout << "Введите число N: ";
  25.     cin >> N;
  26.     cout << "Сумма всех нечетных целых чисел в пределах от M до N включительно: " << f(M, N) << endl;
  27.     system("pause");
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement