- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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
Advertisements