In this post, we will learn how to print the first 10 natural numbers using C Programming language.
Natural numbers are the numbers which are used for counting and are a part of real numbers. For example: 1, 2, 3, and so on.
This program will print the first 10 natural numbers using the following approaches:
- Using For Loop
- Using While Loop
- Using Do While Loop
So, without further ado, let’s begin this tutorial.
C Program to Print First 10 Natural Numbers
// C Program to Print First 10 Natural Numbers #include <stdio.h> int main(){ int i; printf("The first 10 Natural Numbers are: \n"); for (i = 1; i <= 10; i++){ printf("%d \n", i); } return 0; }
Output
The first 10 Natural Numbers are:
1
2
3
4
5
6
7
8
9
10
How Does This Program Work ?
int i;
In this program, we have declared an int data type variable named i.
printf("The first 10 Natural Numbers are: \n"); for (i = 1; i <= 10; i++){ printf("%d \n", i); }
Then, we used for loop to find all the natural numbers lying between 1 and 10 (including both 1 and 10). And the numbers are displayed on the screen using printf() function.
C Program to Print First 10 Natural Numbers Using While Loop
// C Program to Print First 10 Natural Numbers Using While Loop #include <stdio.h> int main(){ int i = 1; printf("The first 10 Natural Numbers are: \n"); while (i <= 10){ printf("%d \n", i); i++; } return 0; }
Output
The first 10 Natural Numbers are:
1
2
3
4
5
6
7
8
9
10
C Program to Print First 10 Natural Numbers Using Do While Loop
// C Program to Print First 10 Natural Numbers Using Do While Loop #include <stdio.h> int main(){ int i = 1; printf("The first 10 natural numbers are: \n"); do { printf("%d \n", i); i++; } while (i <= 10); return 0; }
Output
The first 10 natural numbers are:
1
2
3
4
5
6
7
8
9
10
Conclusion
I hope after going through this post, you understand how to print the first 10 natural numbers using the C Programming language.
If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.
Also Read:
- C Program to Find Area of Rhombus
- C Program to Concatenate Two Strings
- C Program to Find Absolute Value of a Number
- C Program to Print First 10 Even Natural Numbers
- C Program to Find Sum and Average of 3 Numbers