Input two integers in one line, separated by a space. The first integer shall represent the starting point, and the other, the ending point.
Print out all even numbers that are within the range of the starting and ending point. Also keep in mind that the starting and ending numbers are also included in your even number evaluation!
#include <iostream>
using namespace std;
int main() {
int M, N;
cout << "Enter two numbers (intervals): ";
cin >> M >> N;
cout << "\nEven numbers between " << M << " and " << N << " are: ";
for (int i = M; i <= N; i++)
{
if (i % 2 == 0)
{
cout << i << " ";
}
}
return 0;
}
Comments
Leave a comment