C++ Exercises: Find the first 10 natural numbers
1. First 10 Natural Numbers
Write a program in C++ to find the first 10 natural numbers.
Visual Presentation:

Sample Solution :-
C++ Code :
#include <iostream> // Preprocessor directive to include the input/output stream header file
using namespace std; // Using the standard namespace to avoid writing std::
int main() // Start of the main function
{
int i; // Declare an integer variable 'i'
cout << "\n\n Find the first 10 natural numbers:\n"; // Display a message to find the first 10 natural numbers
cout << "---------------------------------------\n"; // Display a separator line
cout << " The natural numbers are: \n"; // Display a message indicating the list of natural numbers
// Loop to print the first 10 natural numbers
for (i = 1; i <= 10; i++)
{
cout << i << " "; // Output each natural number followed by a space
}
cout << endl; // Move to the next line after printing the numbers
}
Sample Output:
Find the first 10 natural numbers: --------------------------------------- The natural numbers are: 1 2 3 4 5 6 7 8 9 10
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C++ program to print the first 10 natural numbers using recursion.
- Write a C++ program to display the first 10 natural numbers in reverse order.
- Write a C++ program to output the first 10 natural numbers using a while loop.
- Write a C++ program that prints the first 10 natural numbers in a single line with a comma separating them.
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: C++ For Loop Exercises Home
Next: Write a program in C++ to find the sum of first 10 natural numbers.
What is the difficulty level of this exercise?