In this post, we will learn how to print the first 10 odd natural numbers using C Programming language.
This program will print the first 10 odd natural numbers using the following approaches:
- Using For Loop
- Using While Loop
- Using Do While Loop
So, without further delay, let’s begin this tutorial.
C Program to Print First 10 Odd Natural Numbers
// C Program to Print First 10 Odd Natural Numbers #include <stdio.h> int main(){ int i; printf("The first 10 odd natural numbers are: \n"); for (i = 1; i <= 10; i++){ printf("%d\n", i * 2 - 1); } return 0; }
Output
The first 10 odd natural numbers are:
1
3
5
7
9
11
13
15
17
19
How Does This Program Work ?
int i;
In this program, we have declared a variable named i.
printf("The first 10 odd natural numbers are: \n"); for (i = 1; i <= 10; i++){ printf("%d\n", i * 2 - 1); }
Then, we used for loop to print the first 10 odd natural numbers.
C Program to Print First 10 Odd Natural Numbers Using While Loop
// C Program to Print First 10 Odd Natural Numbers Using While Loop #include <stdio.h> int main(){ int i = 1; printf("The first 10 odd natural numbers are: \n"); while (i <= 10){ printf("%d\n", 2*i - 1); i++; } return 0; }
Output
The first 10 odd natural numbers are:
1
3
5
7
9
11
13
15
17
19
C Program to Print First 10 Odd Natural Numbers Using Do While Loop
// C Program to Print First 10 Odd Natural Numbers Using Do While Loop #include <stdio.h> int main(){ int i = 1; printf("The first 10 odd natural numbers are: \n"); do { printf("%d\n", i * 2 - 1); i++; } while (i <= 10); return 0; }
Output
The first 10 odd natural numbers are:
1
3
5
7
9
11
13
15
17
19
Conclusion
I hope after going through this post, you understand how to print the first 10 odd natural numbers using 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 assist you.
Also Read: