C++ Program to Print N Natural Numbers

C++ Program to print the natural number .Natural numbers, which include all positive integers from 1 to infinity, are a part of the number system. Natural numbers, which do not include zero or negative numbers, are also known as counting numbers. They are only positive integers, not zero, fractions, decimals, or negative numbers, and they are a part of real numbers.

#include <iostream>
using namespace std;

int main()
{
int i, n, sum = 0;
cout << "Enter the positive number ";
cin >> n;
for (i = 1; i <= n; ++i)
{
sum += i;
}
cout << "Sum = " << sum;
return 0;
}

 

Output:

Enter the positive number 45
Sum = 1035

Zero is natural number or not

Some mathematicians regard zero to be a natural number due to its status as a whole number and the fact that it is not a negative number. To answer the question, yes, zero is a natural number on a number line and when identifying numbers in a set; nevertheless, it is not used to count objects.

+= operator in c++ programming

The addition assignment operator ( += ) assigns the result of adding the value of the right operand to a variable. The behaviour of the addition assignment operator is determined by the types of the two operands. It’s possible to combine items by adding or concatenating them.

Similar Programs