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
Leave a comment