C++ Program to Print First 10 Odd Natural Numbers

Write a C++ program to print first 10 odd natural numbers using for loop.

#include<iostream>
using namespace std;

int main()
{
	cout << "The First 10 Odd Natural Numbers are\n";
	
	for (int i = 1; i <= 10; i++)
	{
		cout << 2 * i - 1 << "\n";
	}
}
C++ Program to Print First 10 Odd Natural Numbers

C++ program to print first 10 odd natural numbers using a while loop

#include<iostream>
using namespace std;

int main()
{
	int i = 1;

	cout << "The First 10 Odd Natural Numbers are\n";

	while (i <= 10)
	{
		cout << 2 * i - 1 << "\n";
		i++;
	}
}
The First 10 Odd Natural Numbers are
1
3
5
7
9
11
13
15
17
19

This C++ program uses the do while loop and displays the first 10 odd natural numbers.

#include<iostream>
using namespace std;

int main()
{
	int i = 1;

	cout << "The First 10 Odd Natural Numbers are\n";

	do
	{
		cout << 2 * i - 1 << "\n";

	} while (++i <= 10);
}
The First 10 Odd Natural Numbers are
1
3
5
7
9
11
13
15
17
19

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.