Write a C++ program that inputs starting and ending number from the user and displays all odd numbers in the given range using while loop.
#include <iostream>
int main()
{
std::cout << "Please enter two numbers: ";
int start, end;
std::cin >> start >> end;
if(!std::cin || end < start)
{
std::cout << "Bad input\n";
return 1;
}
std::cout << "Odd numbers:\n";
while(start <= end)
{
if(start % 2 != 0)
{
std::cout << start << "\n";
}
++start;
}
return 0;
}
Comments