C++ Program to Print First 10 Natural Numbers

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

#include<iostream>
using namespace std;

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

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

#include<iostream>
using namespace std;

int main()
{
	cout << "The First 10 Natural Numbers are\n";

	int i = 1;
	while (i <= 10)
	{
		cout << i << "\n";
		i++;
	}
}
The First 10 Natural Numbers are
1
2
3
4
5
6
7
8
9
10

This C++ program displays the first 10 natural numbers using a do while loop.

#include<iostream>
using namespace std;

int main()
{

	cout << "The First 10 Natural Numbers are\n";
	int i = 1;
	
	do
	{
		cout << i << "\n";

	} while (++i <= 10);
}
The First 10 Natural Numbers are
1
2
3
4
5
6
7
8
9
10

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.