C++ Program to Print First N Odd Numbers using While Loop

C++ Program to Print First N Odd Numbers using While Loop

Write C++ Program to Print First N Odd Numbers using While Loop

// CPP Program to Print First N Odd Numbers using While Loop

#include <iostream>

using namespace std;

int main()
{
	int n;

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

	int i = 1;
	int Count = 0;

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

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

Output:

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