

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Natural Numbers in C++ Program
Numbers that are greater than 0 are called natural numbers. The natural number are
1, 2, 3, 4, 5, 6, 7...
Algorithm
- Initialise the number n.
- Write a loop that iterates from 1 to n.
- Print the numbers.
- Increment the iterative variable.
Implementation
Following is the implementation of the above algorithm in C++
#include <bits/stdc++.h> using namespace std; void printNaturalNumbers(int n) { for (int i = 1; i <= n; i++) { cout << i; } cout << endl; } int main() { int n = 10; printNaturalNumbers(n); return 0; }
Output
If you run the above code, then you will get the following result.
1 2 3 4 5 6 7 8 9 10
- Related Questions & Answers
- C++ Program to Calculate Sum of Natural Numbers
- Sum of first n natural numbers in C Program
- Program for weighted mean of natural numbers in C++
- C++ program to Find Sum of Natural Numbers using Recursion
- C Program for cube sum of first n natural numbers?
- C++ Program for cube sum of first n natural numbers?
- Sum of squares of first n natural numbers in C Program?
- Program to find sum of first n natural numbers in C++
- Program for cube sum of first n natural numbers in C++
- C++ Program for Sum of squares of first n natural numbers?
- C Program for the cube sum of first n natural numbers?
- Java Program to Calculate the Sum of Natural Numbers
- C++ Program to get number at position k after positioning n natural numbers
- Java program to find the sum of n natural numbers
- Python Program for cube sum of first n natural numbers
Advertisements