C++ Program to Print Odd Numbers Between 1 to n using While Loop

Write C++ Program to Print Odd Numbers Between 1 to n using While Loop

// CPP Program to Print Odd Numbers Between 1 to n using While Loop

#include <iostream>

using namespace std;

int main()
{
	int n;

	cout << "Enter the number :--> ";
	cin >> n;

	int i = 1;

	cout << "The odd numbers are :--> ";

	while(i < n)
	{
		if(i % 2 != 0)
		{
			cout << i << " ";
		}
		i++;
	}

	return 0;

}

Output:

Enter the number :--> 21
The odd numbers are :--> 1 3 5 7 9 11 13 15 17 19

≪ Previous | Next ≫