In this tutorial you will learn about the C program to print Natural Numbers from 1 to N and its application with practical example.
C Program to print Natural Numbers from 1 to N
In this tutorial, we will learn to create a C program that will print Natural Numbers from 1 to N using C programming.
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop in C programming.
- Arithmetic operations in C Programming.
What is a Natural number?
The natural numbers are all those positive numbers from 1 to infinity. The set of natural numbers contains all whole positive numbers. The number with decimal points does not come under the natural numbers.
1. Declaring the variables for the program.
2. Taking the input number from the user.
3. Passing that number to a for loop.
4. Generating the series for natural numbers.
5. Printing the result numbers.
6. End Program.
Program to print Natural Numbers from 1 to N.
In this program, we will first take the point up to which we want to generate the series from the user. Then we will generate the series up to that point. At last, we will print that natural numbers in sequence.
With the help of this program, we can print Natural Numbers from 1 to N.
/* C program to print Natural Numbers from 1 to N */
//declaring the required variable for the program
int n, i;
n = it will hold the series last point.
i = it will hold the integer value for the for loop.
/* Taking input number from the user for the program. */
printf("Enter a positive integer: ");
/* Scanning the value the program. */
/* Generating the series upto that point. */
for (i = 1; i <= n; ++i)
/* Printing the series of the natural numbers. */
printf("%d ", i);
In the above program, we have first initialized the required variable.
- n = it will hold the integer value.
- i = it will hold the integer value.
Input number from the user.
Program Logic Code.